lucy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Karman <pe...@peknet.com>
Subject Re: [lucy-user] Searching for blank fields
Date Mon, 09 Jan 2012 21:07:46 GMT
On 1/9/12 2:25 PM, Jason McIntosh wrote:
> Howdy Lucy-users,
>
> My client requires the ability to search for blank fields. In other
> words, they'd like to construct search queries that parse as e.g.
> "Show me all results with the title 'MyTitle' but no description",
> and this would return as hits all items whose "title" field contains
> "MyTitle", and whose "description" field is completely blank.
>
> These sort of null-searches don't appear to be an out-of-the-box
> feature of Lucy's default query parser; a naive query like
> "title:MyTitle AND description:" doesn't work as I hope. So it looks
> like I will have to knit some custom magic here, or perhaps use an
> extension module. I write this list in the hope for some introductory
> pointers; I'm a little unsure where to start, or whether this is a
> solved problem and I'm not finding it.
>

I use Search::Query::Dialect::Lucy[0] to do this, in conjunction with 
this kind of query mangling:

  my $query_str = get_user_input();

# syntactic sugar for finding empty fields
  $query_str =~ s/(\w+)\s*[:=]\s*NULL/$1!=?*/g;
  $query_str =~ s/(\w+)\s*\![:=]\s*NULL/$1=?*/g;

# turn string into a Lucy query
  my $query = Search::Query->parser( dialect => 'Lucy' )
    ->parse($query_str);
  my $lucy_query = $query->as_lucy_query();
  my $hits = $lucy_searcher->hits( query => $lucy_query );


So you can search for:

  description=NULL and title=MyTitle

and get what you're after.

[0] https://metacpan.org/module/Search::Query::Dialect::Lucy


-- 
Peter Karman  .  http://peknet.com/  .  peter@peknet.com

Mime
View raw message