lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dennis yermakov <dem...@gmail.com>
Subject MultiPhraseQuery:Rewrite to BooleanQuery
Date Mon, 12 Jan 2015 13:05:39 GMT
Hi folks!
I have a multiphrase query, for example, from units:

Directory indexStore = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), indexStore);
add("blueberry chocolate pie", writer);
add("blueberry chocolate tart", writer);
IndexReader r = writer.getReader();
writer.close();

IndexSearcher searcher = newSearcher(r);
MultiPhraseQuery q = new MultiPhraseQuery();
q.add(new Term("body", "blueberry"));
q.add(new Term("body", "chocolate"));
q.add(new Term[] {new Term("body", "pie"), new Term("body", "tart")});
assertEquals(2, searcher.search(q, 1).totalHits);
r.close();
indexStore.close();

I need to know on which phrase query will be match. Explanation doesn't
return exact information, only that is match by this query. So can I
rewrite this query to Boolean?, like

BooleanQuery q = new BooleanQuery();

PhraseQuery pq1 = new PhraseQuery();
pq1.add(new Term("body", "blueberry"));
pq1.add(new Term("body", "chocolate"));
pq1.add(new Term("body", "pie"));
q.add(pq1, BooleanClause.Occur.SHOULD);

PhraseQuery pq2 = new PhraseQuery();
pq2.add(new Term("body", "blueberry"));
pq2.add(new Term("body", "chocolate"));
pq2.add(new Term("body", "tart"));
q.add(pq2, BooleanClause.Occur.SHOULD);

In this case I'll exact know on which query I have a match. But main
querstion is, Is this rewrite is equal/true?
Thanks.

-- 
dennis yermakov
mailto: demesg@gmail.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message