QueryParser(3pm)
β¨ QueryParser π
(that's the QueryParser(3pm) page bestie, welcome)
okay so real talk β this is Lucene::QueryParser, the module that takes a Lucene query and hands you back a Perl data structure. it's giving translator energy. it's giving I speak both languages fluently. π¦
πΈ NAME πΈ
Lucene::QueryParser β turn a Lucene query into a Perl data structure. no cap, that's literally the whole job description.
β¨ SYNOPSIS β¨
use Lucene::QueryParser;
my $structure = parse_query("red and yellow and -(coat:pink and green)");
and $structure will be, and I cannot stress this enough, exactly this:
[ { query => 'TERM', type => 'NORMAL', term => 'red' },
{ query => 'TERM', type => 'NORMAL', term => 'yellow' },
{ subquery => [
{ query => 'TERM', type => 'NORMAL', term => 'pink', field => 'coat' },
{ query => 'TERM', type => 'NORMAL', term => 'green' }
], query => 'SUBQUERY', type => 'PROHIBITED'
}
]
look at that structure. she's organized. she's nested. she ate. π
π DESCRIPTION π
so this module parses a Lucene query β as defined over here: http://lucene.sourceforge.net/cgi-bin/faq/faqmanager.cgi?file=chapter.search&toc=faq#q5 β and turns it into something Perl can actually vibe with.
it deals with fields, types, phrases, subqueries, and so on. basically everything handled by the "SimpleQuery" class in Lucene. the data structure is similar to the one up there in the synopsis, and it's pretty self-explanatory ngl, you'll clock it immediately.
then there's the other function, "deparse_query", which does the reverse glow-up: it takes one of these data structures and turns it back into a Lucene query string. super useful if you've just been mucking about with the data, which, bestie, you will be. π
π§ PLUCENE π§
okay important note for the Plucene girlies: the big arrayref and the hashes in the output of "parse_query" are actually objects. plot twist!
they are not "Plucene::Query" objects though β because if they were, then everybody who just wanted to do search queries would have to pull in Plucene, which is a bit unfair. rude even. so instead: you can turn them into "Plucene::Query"s yourself by calling "to_plucene" on them. π«
and the argument to "to_plucene" should be the default field to search if none is supplied. don't forget it, she needs to know where to look.
π EXPORT π
exports the "parse_query" and "deparse_query" functions. two icons, both free.
π«Ά AUTHOR π«Ά
Simon Cozens, <simon@kasei.com>
π COPYRIGHT AND LICENSE π
Copyright 2003 by Kasei
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole page, bestie, every last flag and fact accounted for. π
okay and for the lil sign-off: this page is from perl v5.36.0, dated 2022-11-27, and it lives at QueryParser(3pm). mwah. π
β¨
π¦ where this page comes from
- debian bookworm: liblucene-queryparser-perl 1.04-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: liblucene-queryparser-perl 1.04-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: liblucene-queryparser-perl 1.04-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: liblucene-queryparser-perl 1.04-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: liblucene-queryparser-perl 1.04-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms