NAME
Search::OpenSearch::Engine - abstract base class
SYNOPSIS
use Search::OpenSearch::Engine;
my $engine = Search::OpenSearch::Engine->new(
index => [qw( path/to/index1 path/to/index2 )],
facets => {
names => [qw( color size flavor )],
sample_size => 10_000,
},
fields => [qw( color size flavor )],
);
my $response = $engine->search(
q => 'quick brown fox', # query
s => 'rank desc', # sort order
o => 0, # offset
p => 25, # page size
h => 1, # highlight query terms in results
c => 0, # return count stats only (no results)
L => 'field|low|high', # limit results to inclusive range
f => 1, # include facets
r => 1, # include results
format => 'XML', # or JSON
link => 'http://yourdomain.foo/opensearch/',
b => 'AND', # or OR
);
print $response;
DESCRIPTION
Search::OpenSearch::Engine is an abstract base class. It defines some sane method behavior based on the SWISH::Prog::Searcher API.
METHODS
This class is a subclass of Rose::ObjectX::CAF. Only new or overridden methods are documented here.
init
Sets up the new object.
init_searcher
Subclasses must implement this method. If the Searcher object acts like a SWISH::Prog::Searcher, then search() will Just Work. Otherwise, your Engine subclass should likely override search() as well.
search( args )
See the SYNOPSIS.
Returns a Search::OpenSearch::Response object based on the format specified in args.
set_limit( args )
Called internally by search(). The args will be three key/value pairs, with keys "field," "low", and "high".
facets
Get/set a Search::OpenSearch::Facets object.
index
Get/set the location of the inverted indexes to be searched. The value is intented to be used in init_searcher().
searcher
The value returned by init_searcher().
fields
Get/set the arrayref of field names to be fetched for each search result.
type
Should return a unique identifier for your Engine subclass. Default is to croak().
link
The base URI for Responses. Passed to Response->link.
get_facets( query, results )
Checks the cache for facets related to query and, if found, returns them. If not found, calls build_facets(), which must be implemented by each Engine subclass.
build_facets( query, results )
Default will croak. Engine subclasses must implement this method to provide Facet support.
build_results( results )
results should be an iterator like SWISH::Prog::Results.
Returns an array ref of hash refs, each corresponding to a single search result.
process_result( hash_of_args )
Called by build_results for each result object. hash_of_args is a list of key/value pairs that includes:
- result
-
The values returned from results->next.
- hiliter
-
A Search::Tools::HiLiter object.
- snipper
-
A Search::Tools::Snipper object.
- XMLer
-
A Search::Tools::XML object.
- fields
-
Array ref of fields defined in the new() constructor.
Returns a hash ref, where each key is a field name.
cache
Get/set the internal CHI object. Defaults to the File driver.
cache_ttl
Get/set the cache key time-to-live. Default is 1 hour.
do_not_hilite
Get/set the hash ref of field names that should not be hilited in a Response.
snipper_config
Get/set the hash ref of Search::Tools::Snipper->new params.
hiliter_config
Get/set the hash ref of Search::Tools::HiLiter->new params.
parser_config
Get/set the hash ref of Search::Tools::QueryParser->new params.
no_hiliting( field_name )
By default, looks up field_name in the do_no_hilite() hash, but you can override this method to implement whatever logic you want.
AUTHOR
Peter Karman, <karman at cpan.org>
BUGS
Please report any bugs or feature requests to bug-search-opensearch at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Search-OpenSearch. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Search::OpenSearch
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2010 Peter Karman.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.