I'm asking this, because QueryBuilder.createFieldQuery in some cases returns MultiPhraseQuery. I need to know on which terms from MultiPhraseQuery match is present. Explanation doesn't give answer on this question. It only returns string, based on these terms, see MultiPhraseQuery.toStirng() method, like:
(termA termB) termC it can be "termA termC" OR "termB termC" So my question is, how can I rewrite MultiPhraseQuery to BooleanQuery with PhraseQuery clauses or something else to get matched terms. Can it possible at all and will these queries equal (scoring, boosting, etc). Thanks. 2015-01-21 17:06 GMT+02:00 Ian Lea <ian....@gmail.com>: > Are you asking if your two suggestions > > 1) a MultiPhraseQuery or > > 2) a BooleanQuery made up of multiple PhraseQuery instances > > are equivalent? If so, I'd say that they could be if you build them > carefully enough. For the specific examples you show I'd say not and > would wonder if you get correct hits, particularly for your > MultiPhraseQuery which looks wrong to me, based on my reading of the > javadoc. But I haven't tried or tested your code - I assume you have. > > > If you are asking something else, please explain more clearly. > > -- > Ian. > > > On Wed, Jan 21, 2015 at 2:50 PM, ku3ia <dem...@gmail.com> wrote: > > ku3ia wrote > >> 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@ > > > > Any ideas? > > > > > > > > -- > > View this message in context: > http://lucene.472066.n3.nabble.com/MultiPhraseQuery-Rewrite-to-BooleanQuery-tp4178898p4180863.html > > Sent from the Lucene - Java Users mailing list archive at Nabble.com. > > > > --------------------------------------------------------------------- > > 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 > > -- dennis yermakov mailto: dem...@gmail.com