pedjjj
pedjjj

Reputation: 1038

Lucene QueryParser or Query: get all effectively required terms

Is there a way to get from a Query instance all those terms that are effectively required for documents to contain? A QueryParser is used to create the Query instance, so the "content" of the query is user driven.

A user could for example give this as a query string

+A +B

then I would like to get [A, B] (e.g. as a string array)

or

A

then just [A] as the result I would need.

Upvotes: 0

Views: 217

Answers (1)

mindas
mindas

Reputation: 26733

Something like this might work (untested):

Query q = ...;
Set<Term> terms = new HashSet<>();
q.extractTerms(terms);
for (Term term : terms) {
  System.out.println(term.field());
}

Upvotes: 0

Related Questions