On 7/25/12 6:33 AM, Nikola Tulechki wrote:
Hello,
Is there a way to specify range queries or query numerical fields like
dates or user age in lucy using< <=> operators and integrate it in a
normal query tree object.
Thanks
Nikola,
You can create a RangeQuery:
https://metacpan.org/module/Lucy::Search::RangeQuery
The Lucy QueryParser doesn't support native syntax for that though, so
if you want a query parser that does, you might want to look at:
https://metacpan.org/module/Search::Query::Parser
https://metacpan.org/module/Search::Query::Dialect::Lucy
where you can do things like:
my $parser = Search::Query->parser( dialect => 'Lucy' );
my $query = $parser->parse( 'foo=(123..456)' );
# then pass to Lucy
my $hits = $lucy_searcher->hits( query => $query->as_lucy_query() );
An important thing to note is that Lucy has only one public field
storage type, which is a string. So if you want to get coherent results
from a range query, make sure you are searching fixed-width strings.
E.g., I format all my dates as YYYYMMDD so that I can do range queries like:
my $all_hits_in_2012 = $parser->parse( 'mydate=(20120101..20121231)' );
HTH,
pek
--
Peter Karman . http://peknet.com/ . [email protected]