Mailing List Archive

r3781 - trunk/perl/lib/KinoSearch/Docs/Cookbook
Author: creamyg
Date: 2008-08-28 15:17:02 -0700 (Thu, 28 Aug 2008)
New Revision: 3781

Modified:
trunk/perl/lib/KinoSearch/Docs/Cookbook/CustomQueryParser.pod
Log:
Modify CustomQueryParser Cookbook entry to use "PrefixQuery" rather than
WildCardQuery, as that's the name used in CustomQuery. Add a conclusion
illustrating usage.


Modified: trunk/perl/lib/KinoSearch/Docs/Cookbook/CustomQueryParser.pod
===================================================================
--- trunk/perl/lib/KinoSearch/Docs/Cookbook/CustomQueryParser.pod 2008-08-28 22:15:30 UTC (rev 3780)
+++ trunk/perl/lib/KinoSearch/Docs/Cookbook/CustomQueryParser.pod 2008-08-28 22:17:02 UTC (rev 3781)
@@ -275,21 +275,21 @@
=head1 Extending the query language.

To add support for trailing wildcards to our query language, first we need to
-modify our grammar, adding a C<wildcard_query> production and tweaking the
+modify our grammar, adding a C<prefix_query> production and tweaking the
C<leaf_query> production to accommodate it.

leaf_query:
phrase_query
- | wildcard_query
+ | prefix_query
| term_query

- wildcard_query:
+ preix_query:
/(\w+\*)/
{ KinoSearch::Search::LeafQuery->new( text => $1 ) }

-Second, we need to override expand_leaf() to accommodate WildCardQueries,
-while deferring to its original implementation on TermQueries and
-PhraseQueries.
+Second, we need to override expand_leaf() to accommodate PrefixQuery,
+while deferring to its original implementation on TermQuery and
+PhraseQuery.

sub expand_leaf {
my ( $self, $leaf_query ) = @_;
@@ -297,11 +297,11 @@
if ( $text =~ /\*$/ ) {
my $or_query = KinoSearch::Search::ORQuery->new;
for my $field ( @{ $self->get_fields } ) {
- my $wildcard_query = WildCardQuery->new(
+ my $prefix_query = PrefixQuery->new(
field => $field,
query_string => $text,
);
- $or_query->add_child($wildcard_query);
+ $or_query->add_child($prefix_query);
}
return $or_query;
}
@@ -310,6 +310,20 @@
}
}

+=head1 IN ACTION
+
+Insert any of our custom parsers into the searcher.cgi to get a feel for how
+they behave:
+
+ my $parser = SimpleQueryParser->new( schema => $searcher->get_schema );
+ my $query = $parser->parse( $cgi->param('q') );
+ my $hits = $searcher->search(
+ query => $query,
+ offset => $offset,
+ num_wanted => $hits_per_page,
+ );
+ ...
+
=head1 COPYRIGHT

Copyright 2008 Marvin Humphrey


_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits