19 Jan 16:35
QueryParser: aliases and OP_AND
Menard, Daniel <Daniel.Menard <at> ehesp.fr>
2010-01-19 15:35:59 GMT
2010-01-19 15:35:59 GMT
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
RSS Feed