SYNOPSIS

  use Lucene::QueryParser;
  my $structure = parse_query("red and yellow and -(coat:pink and green)");

$structure will be:

[ { 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' } ]

DESCRIPTION

This module parses a Lucene query, as defined by http://lucene.sourceforge.net/cgi-bin/faq/faqmanager.cgi?file=chapter.search&toc=faq#q5

It deals with fields, types, phrases, subqueries, and so on; everything handled by the \*(C`SimpleQuery\*(C' class in Lucene. The data structure is similar to the one given above, and is pretty self-explanatory.

The other function, \*(C`deparse_query\*(C' turns such a data structure back into a Lucene query string. This is useful if you've just been mucking about with the data.

\$1

Note for people using Plucene: the big arrayref and the hashes in the output of \*(C`parse_query\*(C' are actually objects. They're not \*(C`Plucene::Query\*(C' objects, because then everyone who wanted to do search queries would have to pull in Plucene, which is a bit unfair. However, they can be turned into \*(C`Plucene::Query\*(C's by calling \*(C`to_plucene\*(C' on them. The argument to \*(C`to_plucene\*(C' should be the default field to search if none is supplied. Exports the \*(C`parse_query\*(C' and \*(C`deparse_query\*(C' functions.

AUTHOR

Simon Cozens, <[email protected]>

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.