You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@solr.apache.org by Paul Mayer <di...@gmail.com> on 2022/03/28 09:47:10 UTC

Querying for complex phrases in order

Dear Solr users,

I am new to Solr and am trying to port search functionality from another
system to Solr 7.5.
In particular, what we want to support are queries of the following nature:

(foo* [OR] bar) [any text] baz

Where foo, bar and baz could be phrases (rather than just terms) and,
crucially, baz *must *occur *anywhere after* foo* or bar.

From my understanding, with the ComplexPhraseQueryParser, I can write

{!complexphrase df=my_text_field inOrder=true}(foo* bar) baz

to query my_text_fields for documents that contain the sequence foo* baz or
bar baz, however, baz here must occur directly after foo* or bar.

Is there any way to combine a ComplexPhraseQuery with a Span or
SurroundQuery to allow for any number of terms between foo*/bar and baz? Or
would this require me to implement a custom search component (I hope I am
using "search component" right here)?

To provide an even more complex example. If the former was possible, would
queries like the following also be achievable with components Solr provides
out of the box:

(foo* [OR] bar) [any text] (5w(term1, term2), baz)

This query should match any document that contains either the phrase foo*
or bar, *followed by *(not necessarily in direct succession, but at any
position after foo* or bar) either

   - term1 [at most 5 terms] term2
   - baz

In isolation, 5w(term1, term2) can be achieved using the
SurroundQueryParser, but is it possible to nest such a surroundquery?

Thanks & best regards,
Paul