Catalyst::Model::SWISH - Catalyst model for Swish-e
# in your Controller sub search : Local { my ($self, $c) = @_; my ($pager, $results, $query, $order, $total, $stime, $btime) = $c->model('SWISH')->search( query => $c->request->params->{q}, page => $c->request->params->{page} || 0, page_size => $c->request->params->{itemsperpage} || 0, limit_to => 'swishtitle', limit_high => 'm', limit_low => 'a', order_by => 'swishrank desc swishtitle asc' ); $c->stash(search => { results => $results, pager => $pager, query => $query, order => $order, hits => $total, search_time => $stime, build_time => $btime } ); }
Catalyst::Model::SWISH provides an easy interface to SWISH::API::Object for searching Swish-e indexes (http://www.swish-e.org/). It is similar to and inspired by Catalyst::Model::Xapian.
The configuration value is passed directly to SWISH::API::Object->new() so see the SWISH::API::Object documentation for possible key/value options.
Path(s) to the Swish-e index(es). Defaults to <MyApp>/index.swish-e.
Default page sizes for Data::Pageset. Defaults to 10.
You may set config options either in your root class config() method prior to setup(), using your Model class name as the key, or set them directly in your Model class config() method.
Examples:
# in MyApp.pm MyApp->config( 'MyApp::Model::SWISH' => { 'indexes' => MyApp->path_to('some/where/index.swish-e')->stringify } ); # same thing in MyApp/Model/SWISH.pm MyApp::Model::SWISH->config( 'indexes' => MyApp->path_to('some/where/index.swish-e')->stringify );
Constructor is called automatically by Catalyst at startup.
Perform a search on the index.
In array context, returns (in order):
a Data::Pageset object
an arrayref of SWISH::API::Result objects.
an arrayref of parsed query terms
an arrayref of property sort order, where each array item is a hashref like:
{ property => asc | desc }
the total number of hits
the search time
the build time
In scalar context, returns a hashref with the same values, with keys:
opts require a query name/value pair at minimum. Other valid params include:
query
Which page to start on. Used in cooperation with page_size set in new().
page_size
Sort results by a property other than rank.
Property name to limit results by.
High value for limit_to.
limit_to
Low value for limit_to.
Calls the results_object seek_result() method, setting it to start_offset.
search_object is a SWISH::API::More::Search object.
opts is a hashref. This method is called within search(). Override it to set per-search options other than the defaults.
Loops over results_object calling next_result(). opts is the same hashref passed to set_search_opts().
Returns a hashref with the following key pairs:
Total number of hits for query.
Total number of results in current search.
Arrayref of result objects.
Calling connect() will DESTROY the cached SWISH::API::Object object and re-cache it, essentially re-opening the Swish-e index.
NOTE: SWISH::API::Object actually makes this unnecessary in most cases, since it inherits from SWISH::API::Stat.
Returns the SWISH::API::Object instance.
Peter Karman <perl@peknet.com>
Thanks to Atomic Learning, Inc for sponsoring the development of this module.
This library is free software. You may redistribute it and/or modify it under the same terms as Perl itself.
http://www.swish-e.org/, SWISH::API::Object
To install Catalyst::Model::SWISH, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Model::SWISH
CPAN shell
perl -MCPAN -e shell install Catalyst::Model::SWISH
For more information on module installation, please visit the detailed CPAN module installation guide.