You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by ku3ia <de...@gmail.com> on 2015/01/20 17:54:00 UTC

MultiPhraseQuery:Rewrite to BooleanQuery

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.



--
View this message in context: http://lucene.472066.n3.nabble.com/MultiPhraseQuery-Rewrite-to-BooleanQuery-tp4180638.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: MultiPhraseQuery:Rewrite to BooleanQuery

Posted by ku3ia <de...@gmail.com>.
Tomoko Uchida wrote
> Hi,
> 
> Strictly speaking, MultiPhraseQuery and BooleanQuery wrapping PhraseQuerys
> are not equal.
> 
> For each query, Query.rewrite() returns different object. (with Lucene
> 4.10.3)
> q1.rewrite(reader).toString() returns:
>     body:"blueberry chocolate (pie tart)", where q1 is your first multi
> phrase query.
> q2.rewrite(reader).toString() returns:
>     body:"blueberry chocolate pie" body:"blueberry chocolate tart", where
> q2 is your second boolean query.
> 
> In practice... I *think* two queries may return same set of documents, but
> I'm not sure about scoring/ranking.
> 
> I suggest you ask to java-user@lucene mailing list as for Lucene API.
> 
> Regards,
> Tomoko
> 
> 
> 
> 2015-01-21 19:12 GMT+09:00 ku3ia &lt;

> demesg@

> &gt;:
> 
>> Any ideas?
>>
>>
>>
>> --
>> View this message in context:
>> http://lucene.472066.n3.nabble.com/MultiPhraseQuery-Rewrite-to-BooleanQuery-tp4180638p4180820.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>

Thanks, I'll try it.



--
View this message in context: http://lucene.472066.n3.nabble.com/MultiPhraseQuery-Rewrite-to-BooleanQuery-tp4180638p4180887.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: MultiPhraseQuery:Rewrite to BooleanQuery

Posted by Tomoko Uchida <to...@gmail.com>.
Hi,

Strictly speaking, MultiPhraseQuery and BooleanQuery wrapping PhraseQuerys
are not equal.

For each query, Query.rewrite() returns different object. (with Lucene
4.10.3)
q1.rewrite(reader).toString() returns:
    body:"blueberry chocolate (pie tart)", where q1 is your first multi
phrase query.
q2.rewrite(reader).toString() returns:
    body:"blueberry chocolate pie" body:"blueberry chocolate tart", where
q2 is your second boolean query.

In practice... I *think* two queries may return same set of documents, but
I'm not sure about scoring/ranking.

I suggest you ask to java-user@lucene mailing list as for Lucene API.

Regards,
Tomoko



2015-01-21 19:12 GMT+09:00 ku3ia <de...@gmail.com>:

> Any ideas?
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/MultiPhraseQuery-Rewrite-to-BooleanQuery-tp4180638p4180820.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: MultiPhraseQuery:Rewrite to BooleanQuery

Posted by ku3ia <de...@gmail.com>.
Any ideas?



--
View this message in context: http://lucene.472066.n3.nabble.com/MultiPhraseQuery-Rewrite-to-BooleanQuery-tp4180638p4180820.html
Sent from the Solr - User mailing list archive at Nabble.com.