Tim Retout: How not to parse search queries
While I remember, I have uploaded the slides from my
talk about Solr and Perl at the London Perl Workshop.
This talk was inspired by having seen and contributed to at least
five different sets of Solr search code at my current job, all of
which (I now believe) were doing it wrong. I distilled this hard-won
knowledge into a 20 minute talk, which - funny story - I actually
delivered twice to work around a cock-up in the printed schedule. I
don't believe any video was successfully taken, but I may be proved
wrong later.
I have also uploaded the Parse::Yapp
grammar mentioned in the talk.
In case you don't have time to read the slides, the right way to
present Solr via Perl is to use the 'edismax' parser, and write your
code a bit like this:
my $solr = WebService::Solr->new($url);
my $s = $query->param('q');
# WebService::Solr::Query objects are useful for
# 'fq' params, but avoid them for main 'q' param.
my $options =
fq => [WebService::Solr::Query->new(...)];
;
$solr->search($s, \%options);
The key thing here is not to put any complicated parsing code in
between the user and Solr. Avoid Search::QueryParser at all costs.
I am getting into the swing of fatherhood - lots of nappy changing. :) I took my two weeks of paternity leave, but spread the second "week" over two weeks by working just afternoons, which gave me lots of time with mummy and baby. We watched a DVD called "The Happiest Baby on the Block", and mastered the techniques therein (mainly swaddling and white noise). So all things considered, we're getting quite a bit of sleep.
Sophie is very curious about my typing, and leans towards anything she's interested in... so she's currently suspended at an angle besides me. Maybe she'll be interested in what her parents do, when she grows up. :) But for now, we're enjoying that she's learned to smile.