Query Containing Multiple Parsers

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Query Containing Multiple Parsers

Nussbaum, Ronen
Hello All,

We have an application that translates user queries to Solr syntax (Lucene query parser) by using ANTLR.
Lately, we wanted to add support for the user to search term(s) that appear in the beginning of the text.
From answers to similar questions, I understood that SpanFirst might be a good solution.
Since the user query usually contains features which I'm nut sure are supported for this parser e.g. json facets, I thought that instead of translating all queries to the xml parser, it would be better to use it only for the Span First.
Is there a way to construct a query that needs two different parsers?
Example:
q={!xmlparser}<SpanFirst  fieldName="text_en" end="5"  boost="1.2"><SpanTerm>Hello</SpanTerm></SpanFirst>
AND
q={!edismax}text_en:"foo bar"~4
I've tried using the "magic" "_query_" but it seems that it uses the luceneqparser and not the xml.

Thanks in advance,
Ronen.


This electronic message may contain proprietary and confidential information of Verint Systems Inc., its affiliates and/or subsidiaries. The information is intended to be for the use of the individual(s) or entity(ies) named above. If you are not the intended recipient (or authorized to receive this e-mail for the intended recipient), you may not use, copy, disclose or distribute to anyone this message or any information contained in this message. If you have received this electronic message in error, please notify us by replying to this e-mail.
Reply | Threaded
Open this post in threaded view
|

Re: Query Containing Multiple Parsers

Chris Hostetter-3

: Is there a way to construct a query that needs two different parsers?
: Example:
: q={!xmlparser}<SpanFirst  fieldName="text_en" end="5"  boost="1.2"><SpanTerm>Hello</SpanTerm></SpanFirst>
: AND
: q={!edismax}text_en:"foo bar"~4

The easies way to do what you're asking about would be to choose one of
those queries for "storking" purposes, and put the other one in an "fq"
simply for filtering.

But you can build a single compelx query using multiple parsers by
leveraging the "lucene" parser's support for nesting queries -- ie: in a
larger boolean query -- and then use local param variables to reference
your other param names...


q=({!edismax qf=text_en v=$my_main_query} OR {!xmlparser v=$my_span_query})
my_main_query="foo bar"~4
my_span_query=<SpanFirst  fieldName="text_en" end="5"boost="1.2"><SpanTerm>Hello</SpanTerm></SpanFirst>

...the important bits that tend to trip people up is to make sure you
don't start your query string with the local param syntax of another
parser, and that you don't pass the input of your nested parsers "inline"
if they contain white space .. hence the parens above and the use of the
'v' local param.

If you tried to do the same thing like either of these queries below, it
wouldn't work because it would confuse the parsing logic...

bad_q1={!edismax qf=text_en v=$my_main_query} OR {!xmlparser v=$my_span_query}

bad_q2=({!edismax qf=text_en}"foo bar"~4 OR {!xmlparser v=$my_span_query})

in "bad_q1" solr would think you wanted the *entire* param value
(including the "OR {!xmlparser..." passed to the "edismax" parsers

in "bad_q2" the nested edismax parser would only be given the input '"foo"
.. and not the ' bar"~4' bit, because the outer most (implicit) lucene
parser doens't understand how much of the input you intended for the
nested parser.


-Hoss
http://www.lucidworks.com/