[Koha-devel] QueryParser does not manage more than 1 operator?

David Cook dcook at prosentient.com.au
Mon Dec 29 05:05:51 CET 2014


Hey Jonathan:

This is certainly a tricky one...

It looks to me that this is probably due to bugs in OpenILS::QueryParser AND
Koha::QueryParser::Driver::PQF::query_plan::node.

For instance, my query "((nb:9780955908651) || (nb:9781742418629 ||
nb:9780702030857))" is getting changed into:

@or @attr 1=7 @attr 4=6 "9780955908651" @and @attr 1=7 @attr 4=6
"9781742418629" @attr 1=7 @attr 4=6 "9780702030857"

This is because line 102 of Koha::QueryParser::Driver::PQF::query_plan::node
is hardcoded to always use "@and". 

"$pqf = (OpenILS::QueryParser::_util::default_joiner eq '|' ? ' @or ' : '
@and ') x ($atom_count - 1) . $pqf;"

It seems to me that the joiner should be set at
Koha::QueryParser::Driver::PQF::query_plan level. It looks like there is
code for that... but it doesn't look like it would ever be used...

It looks like there might also be a bug in OpenILS::QueryParser, as it
doesn't look like it's setting a second joiner correctly either after it
already detects a first joiner. 

I've been looking at this for hours... as I think this would be a real
blocker against using QueryParser at all... but that's about the best I can
come up with so far. I think QueryParser would need more analysis, and the
PQF driver would probably need some tweaks.

David Cook
Systems Librarian
Prosentient Systems
72/330 Wattle St, Ultimo, NSW 2007

> -----Original Message-----
> From: koha-devel-bounces at lists.koha-community.org [mailto:koha-devel-
> bounces at lists.koha-community.org] On Behalf Of Jonathan Druart
> Sent: Wednesday, 24 December 2014 2:45 AM
> To: koha-devel at lists.koha-community.org
> Subject: [Koha-devel] QueryParser does not manage more than 1 operator?
> 
> Hello dev,
> 
> I tried to hack C4::Search to permit to search for a record from its ISBN
> whatever the form used (10 vs 13, with vs without dash).
> I have easily done it for the non QP form (~3 lines in
C4::Search::buildQuery).
> It looked easy to do for using the QP too (almost the same ~3 lines in
> C4::Search::parseQuery).
> But I think there is a bug somewhere because the PQF query generated by
> QP is wrong, or I did not use the correct syntax.
> 
> If I search for
>   nb:foo && nb:bar => OK
>   nb:foo || nb:bar => OK
> But with a 3rd term:
>   nb:foo && nb:bar && nb:foobar => OK
>   nb:foo && nb:bar || nb:foobar => KO (same as nb:foo && nb:bar &&
> nb:foobar)
>   nb:foo || nb:bar || nb:foobar => KO (same as nb:foo || nb:bar &&
> nb:foobar)
> 
> Actually the second operator is always replaced with && (AND)
> 
> I don't know the the bug is come from Koha::QueryParser or
> OpenILS::QueryParser.
> Could someone familiar with this code help me giving some tricks?
> 
> Regards,
> Jonathan
> 
> PS:
> The tests are:
> is($QParser->target_syntax('
> biblioserver', 'au:smith || ti:johnson || au:doe'), '@or @attr 1=1003
@attr
> 4=6 "smith" @or @attr 1=4 @attr 4=6 "johnson" @attr 1=1003 @attr 4=6
> "doe"', 'query with 2 boolean ||');
> 
> is($QParser->target_syntax('biblioserver', 'au:smith && ( ti:johnson
> || au:doe )'),  '@and @attr 1=1003 @attr 4=6 "smith" @or @attr 1=4
> @attr 4=6 "johnson" @attr 1=1003 @attr 4=6 "doe"', 'query with 2 boolean
> && + ||');
> 
> And the result is:
> #   Failed test 'query with 2 boolean ||'
> #   at /home/koha/src/t/QueryParser.t line 56.
> #          got: '@or @attr 1=1003 @attr 4=6 "smith" @and @attr 1=4
> @attr 4=6 "johnson" @attr 1=1003 @attr 4=6 "doe"'
> #     expected: '@or @attr 1=1003 @attr 4=6 "smith" @or @attr 1=4
> @attr 4=6 "johnson" @attr 1=1003 @attr 4=6 "doe"'
> 
> #   Failed test 'query with 2 boolean && + ||'
> #   at /home/koha/src/t/QueryParser.t line 59.
> #          got: '@and @attr 1=1003 @attr 4=6 "smith" @and @attr 1=4
> @attr 4=6 "johnson" @attr 1=1003 @attr 4=6 "doe"'
> #     expected: '@and @attr 1=1003 @attr 4=6 "smith" @or @attr 1=4
> @attr 4=6 "johnson" @attr 1=1003 @attr 4=6 "doe"'
> _______________________________________________
> Koha-devel mailing list
> Koha-devel at lists.koha-community.org
> http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
> website : http://www.koha-community.org/ git : http://git.koha-
> community.org/ bugs : http://bugs.koha-community.org/




More information about the Koha-devel mailing list