The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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->param('q'),
      page          => $c->request->param('page') || 0,
      page_size     => $c->request->param('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.

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

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.

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.

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