You could use Lucene::QueryParser but you would have to modify the boolean operators to all caps:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Lucene::QueryParser; my $struct = parse_query('(A OR B AND (B OR C*))' ); print Dumper( $struct );
produces:
$VAR1 = bless( [ bless( { 'subquery' => bless( [ bless( { 'query' => 'TERM', 'type' => 'NORMAL', 'term' => 'A' }, 'Lucene::QueryParser::Term' ), bless( { 'conj' => 'OR', 'query' => 'TERM', 'type' => 'NORMAL', 'term' => 'B' }, 'Lucene::QueryParser::Term' ), bless( { 'conj' => 'AND', 'subquery' => bless( [ bless( { 'query' => 'TERM', 'type' => 'NORMAL', 'term' => 'B' }, 'Lucene::QueryParser::Term' ), bless( { 'conj' => 'OR', 'query' => 'PREFIX', 'type' => 'NORMAL', 'term' => 'C' }, 'Lucene::QueryParser::Prefix' ) ], 'Lucene::QueryParser::TopLevel' ), 'query' => 'SUBQUERY', 'type' => 'NORMAL' }, 'Lucene::QueryParser::Subquery' ) ], 'Lucene::QueryParser::TopLevel' ), 'query' => 'SUBQUERY', 'type' => 'NORMAL' }, 'Lucene::QueryParser::Subquery' ) ], 'Lucene::QueryParser::TopLevel' );
In reply to Re: how to parse a query
by derby
in thread how to parse a query
by arunmep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |