Trying to implement the example on https://lucene.apache.org/core/6_6_1/core/org/apache/lucene/search/MultiPhraseQuery.html

// A generalized version of PhraseQuery, with the possibility of adding more than one term at the same position that are treated as a disjunction (OR). To use this class to search for the phrase "Microsoft app*" first create a Builder and use

// MultiPhraseQuery.Builder.add(Term) on the term "microsoft" (assuming lowercase analysis), then find all terms that have "app" as prefix using LeafReader.terms(String), seeking to "app" then iterating and collecting terms until there is no longer that prefix,

// and finally use MultiPhraseQuery.Builder.add(Term[]) to add them. MultiPhraseQuery.Builder.build() returns the fully constructed (and immutable) MultiPhraseQuery.


IndexSearcher is = new IndexSearcher(indexReader);

MultiPhraseQuery.Builder builder = new MultiPhraseQuery.Builder();
builder.add(new Term("body", "one"), 0);

Terms terms = LeafReader.terms("body"); // will this be slow? and how do we incorporate token/word "app" here?

// i STILL dont see how to get individual Term objects from terms object and plus do i need to declare LeafReader object?

Term[] termArr = new Term[k]; // i will get this filled via using Terms.iterator
builder.add(termArr);
MultiPhraseQuery mpq = builder.build();
TopDocs hits = is.search(mpq, 20);// 20 hits


Best regards


On 9/18/18 4:16 PM, baris.ka...@oracle.com wrote:
Hi,-

 how does MultiPhraseQuery treat synonyms?

is the following possible?

... (created index with synonyms and indexReader object has the index)

IndexSearcher is = new IndexSearcher(indexReader);

MultiPhraseQuery.Builder builder = new MultiPhraseQuery.Builder();
builder.add(new Term("body", "one"), 0);
builder.add(new Term("body", "two"), 1);
MultiPhraseQuery mpq = builder.build();
TopDocs hits = is.search(mpq, 20);// 20 hits

Best regards


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to