Hello, I'm wondering about how the QueryParser parses a query containing an "alias" when the default operator is OP_AND (by "alias", I mean a search field mapped to multiple term prefixes). With the following php code : <?php $parser=new XapianQueryParser(); $parser->set_default_op(XapianQuery::OP_AND); $parser->add_prefix('alias', 'AUT1:'); $parser->add_prefix('alias', 'AUT2:'); echo $parser->parse_query('alias:(john smith)')->get_description(); ?> I get: Xapian::Query(((AUT1:john:(pos=1) OR AUT2:john:(pos=1)) AND (AUT1:smith:(pos=2) OR AUT2:smith:(pos=2)))) i.e. (AUT1:john OR AUT2:john) AND (AUT1:smith OR AUT2:smith) I was expecting something like: Xapian::Query(((AUT1:john:(pos=1) AND AUT1:smith:(pos=2)) OR (AUT2:john:(pos=1) AND AUT2:smith:(pos=2)))) i.e. (AUT1:john AND AUT1:smith) OR (AUT2:john AND AUT2:smith) I think that I understand why I get the current result: "alias:(john smith)" is parsed as "alias:john AND alias:smith" and the alias is then expanded. But for my application, it produces some "noise" because a record containing the following data : "Aut1=john lennon, Aut2=will smith" will appear in the Mset. So my questions: is the current QueryParser's behaviour the intended one? Is there anything I can do to get the result I expect? Of course, the parsing is fine when default_op is OP_OR (as it is by default), but results are also "strange for me" if I try with OP_PHRASE: Xapian::Query(((AUT1:john:(pos=1) PHRASE 2 AUT1:smith:(pos=2)) OR (AUT2:john:(pos=1) PHRASE 2 AUT1:smith:(pos=2)) OR (AUT2:john:(pos=1) PHRASE 2 AUT2:smith:(pos=2)) OR (AUT1:john:(pos=1) PHRASE 2 AUT2:smith:(pos=2)))) i.e :(AUT1:john PHRASE AUT1:smith) OR (AUT2:john PHRASE AUT1:smith) OR (AUT2:john PHRASE AUT2:smith) OR (AUT1:john PHRASE AUT2:smith) Thanks, -- Daniel M?nard
2010/1/19 Menard, Daniel <Daniel.Menard at ehesp.fr>:> Hello, > > I'm wondering about how the QueryParser parses a query containing an "alias" when the default operator is OP_AND > (by "alias", I mean a search field mapped to multiple term prefixes).The short answer: it always combines each word of the options with OP_OR, and there is no configuration for this currently. I can see why it's not helpful in your situation, though. I can't think of an easy solution inside the query parser, though. What you want would seem to be to take each group of words in the query (ie, each group of words not separated by an operator) and parse them with each prefix, and then combine those options with OP_OR. We were having some discussions on this subject on IRC recently - it would be nice to have a way to specify how the queryparser deals with each set of words it finds. One workaround for you might be to parse the query multiple times, each time using one of the prefixes for the field, and OR the resulting queries together. This would produce the result you wanted in the case of a search for "alias:(john smith)". This approach would even work in the presence of other filters in the query. It would fall down (or, at least, become overly complex) if you wanted multiple expansions for more than one field, though.> So my questions: is the current QueryParser's behaviour the intended one? Is there anything I can do to get the result I expect?> Of course, the parsing is fine when default_op is OP_OR (as it is by default), but results are also "strange for me" if I try with OP_PHRASE: > > Xapian::Query(((AUT1:john:(pos=1) PHRASE 2 AUT1:smith:(pos=2)) OR (AUT2:john:(pos=1) PHRASE 2 AUT1:smith:(pos=2)) OR (AUT2:john:(pos=1) PHRASE 2 AUT2:smith:(pos=2)) OR (AUT1:john:(pos=1) PHRASE 2 AUT2:smith:(pos=2))))This is the same problem, but looks a bit weirder because the query has been rearranged by Xapian to put the PHRASE parts at the bottom of the tree. (A OR B) PHRASE (C OR D) is equivalent to (A PHRASE C) OR (A PHRASE D) OR (B PHRASE C) OR (B PHRASE D). -- Richard
Seemingly Similar Threads
- [PATCH] Add set_max_wildcard_expansion method to the queryparser.
- How to enable stemming with default_op set to OP_NEAR
- Re: [Xapian-commits] 9476: trunk/xapian-core/ trunk/xapian-core/include/xapian/ trunk/xapian-core/queryparser/ trunk/xapian-core/tests/
- Does Xapian support retrieval optional?
- How to make QueryParser select entire word like "H.O.T"