NAME

Catalyst::Model::SWISH - Catalyst model for Swish-e

SYNOPSIS

# 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
       }
   );
}

DESCRIPTION

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.

CONFIGURATION

The configuration value is passed directly to SWISH::API::Object->new() so see the SWISH::API::Object documentation for possible key/value options.

indexes

Path(s) to the Swish-e index(es). Defaults to <MyApp>/index.swish-e.

page_size

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
   );

METHODS

new

Constructor is called automatically by Catalyst at startup.

search( opts )

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:

pager
results
query
order
hits
search_time
build_time

opts require a query name/value pair at minimum. Other valid params include:

page

Which page to start on. Used in cooperation with page_size set in new().

order_by

Sort results by a property other than rank.

limit_to

Property name to limit results by.

limit_high

High value for limit_to.

limit_low

Low value for limit_to.

seek_result( results_object, start_offset )

Calls the results_object seek_result() method, setting it to start_offset.

set_search_opts( search_object, opts )

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.

get_results( results_object, opts )

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:

hits

Total number of hits for query.

count

Total number of results in current search.

results

Arrayref of result objects.

connect

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.

AUTHOR

Peter Karman <perl@peknet.com>

Thanks to Atomic Learning, Inc for sponsoring the development of this module.

LICENSE

This library is free software. You may redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

http://www.swish-e.org/, SWISH::API::Object