| App-ZofCMS-Plugin-Search-Indexer documentation | Contained in the App-ZofCMS-Plugin-Search-Indexer distribution. |
App::ZofCMS::Plugin::Search::Indexer - plugin that incorporates Search::Indexer module's functionality
plugins => [ qw/Search::Indexer/ ],
plug_search_indexer => {
# most of these values are optional
dir => 'index_files',
cell => 'd',
key => 'search_indexer',
obj_args => [],
exact_match => 0,
add => { id1 => 'text to index', },
remove => [ qw/id1 id2 id3/ ],
search => 'foo bar baz',
},
The module is a plugin for App::ZofCMS that incorporates (partial) Search::Indexer functionality in a form of ZofCMS plugin. In other words, plugin allows one to create a search index from a bunch of data and later on perform search on that index. See docs for Search::Indexer for more details.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template as well as familiar with Search::Indexer, at least lightly.
pluginsplugins => [ qw/Search::Indexer/ ],
You need to add the plugin into the list of plugins to execute.
plug_search_indexer plug_search_indexer => {
# most of these values are optional
dir => 'index_files',
cell => 'd',
key => 'search_indexer',
obj_args => [],
exact_match => 0,
add => { id1 => 'text to index', },
remove => [ qw/id1 id2 id3/ ],
search => 'foo bar baz',
},
plug_search_indexer => sub {
my ( $t, $q, $conf ) = @_;
return {
add => { id1 => 'text to index', },
};
},
Mandatory. The plug_search_indexer first-level key can be specified in either ZofCMS
Template or Main Config File (or both). Its value can be either a subref or a hashref; if the
value is a subref it will be evaluated and it must return a hashref (or undef/empty list). This
hashref will be treated as if you directly assigned it to plug_search_indexer key. The
@_ of that subref will contain the following $t, $q, $conf where $t is ZofCMS
Template hashref, $q is a hashref of query parameters and $conf is App::ZofCMS::Config
object. Possible keys/values of plug_search_indexer hashref are as follows:
dirdir => 'index_files',
Optional. Specifies the directory where index files are located. Corresponds to dir
argument of Search::Indexer new() method. Defaults to: index_files (and is relative
to index.pl file).
obj_argsobj_args => [],
Optional. Takes an arrayref as a value, this arrayref will be directly dereferenced into
Search::Indexer's constructor (new() method). The writeMode argument will be set
by the plugin to a true value if add or remove keys (see below) are set. The dir
argument will be derived from plugin's dir key. The arrayref will be dereferenced after
the dir and writeMode arguments, thus you can use obj_args to override them.
See documentation for Search::Indexer for possible values that you can set in
obj_args. Defaults to: [] (empty arrayref).
cellcell => 'd',
Optional. Specifies first-level ZofCMS Template key into which to put search results (when
search
is performed). See key argument below. Defaults to: d
keykey => 'search_indexer',
Optional. Specifies the name of the key inside cell first-level key into which to put search results (when search
is performed). See cell argument below. Basically, if cell is set to d and
key is set to search_indexer then search results will be stored in
$t->{d}{search_indexer} where $t is ZofCMS Template hashref. Defaults to:
search_indexer
exact_matchexact_match => 0,
Optional. Takes either true or false values. Will be given as second parameter to
Search::Indexer's search() method; thus if it is set to true all the search words without
prefix will have + added to them. Defaults to: 0
add add => {
id1 => 'text to index',
id2 => 'other text to index',
},
Optional. When specified, instructs the plugin to add stuff into index. Takes a hashref as a value where keys are IDs and values are text to index under those IDs.
remove remove => [ qw/id1 id2 id3/ ],
remove => {
id1 => 'containing text',
id2 => 'other containing text'
},
Optional. Takes either a hashref or an arrayref as a value. Elements of the arrayref would
be IDs of records to remove from the index. You'd use the hashref form when positions
argument in obj_args arrayref would be set to a false value (by default it's true); when
that's the case, the keys of hashref would be IDs and values would be corresponding texts.
See remove() method and positions argument to new() method in Search::Indexer
searchsearch => 'foo bar baz',
Optional. Takes a string as a value. This string will be given to
Search::Indexer's search() method as a first argument, i.e. the text for which to search.
The return value will be the same as return value of Search::Indexer's search() method
and it will be assigned to $t->{ <cell> }{ <key> } where $t is ZofCMS Template
hashref and <cell> and <key> are cell and key plugin's arguments
respectively.
'Zoffix, <'zoffix at cpan.org'>
(http://zoffix.com/, http://haslayout.net/, http://zofdesign.com/)
Please report any bugs or feature requests to bug-app-zofcms-plugin-search-indexer at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-Search-Indexer. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc App::ZofCMS::Plugin::Search::Indexer
You can also look for information at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-Search-Indexer
http://cpanratings.perl.org/d/App-ZofCMS-Plugin-Search-Indexer
http://search.cpan.org/dist/App-ZofCMS-Plugin-Search-Indexer
Copyright 2009 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| App-ZofCMS-Plugin-Search-Indexer documentation | Contained in the App-ZofCMS-Plugin-Search-Indexer distribution. |
package App::ZofCMS::Plugin::Search::Indexer; use warnings; use strict; our $VERSION = '0.0102'; use base 'App::ZofCMS::Plugin::Base'; use Search::Indexer; sub _key { 'plug_search_indexer' } sub _defaults { return ( dir => 'index_files', cell => 'd', key => 'search_indexer', obj_args => [], exact_match => 0, # add => {}, # remove => [], # search => '' || [], ); } sub _do { my ( $self, $conf, $t, $q, $config ) = @_; return unless defined $conf->{add} or defined $conf->{remove} or defined $conf->{search}; my $ix = Search::Indexer->new( dir => $conf->{dir}, ( writeMode => ( defined $conf->{add} or defined $conf->{remove} ) ? 1 : 0 ), @{ $conf->{obj_args} || [] } ); if ( defined $conf->{remove} ) { $conf->{remove} = [ $conf->{remove} ] unless ref $conf->{remove}; if ( ref $conf->{remove} eq 'HASH' ) { for ( keys %{ $conf->{remove} || {} } ) { $ix->remove( $_, $conf->{remove}{ $_ } ); } } else { for ( @{ $conf->{remove} || [] } ) { $ix->remove( $_ ); } } } for ( keys %{ $conf->{add} || {} } ) { $ix->add( $_, $conf->{add}{ $_ } ); } if ( defined $conf->{search} ) { do_search( $conf, $t, $ix ); } } sub do_search { my ( $conf, $t, $ix ) = @_; my $search = $conf->{search}; if ( ref $search ) { for ( @$search ) { push @{ $t->{ $conf->{cell} }{ $conf->{key} } }, $ix->search( $_, $conf->{exact_match} ); } } else { $t->{ $conf->{cell} }{ $conf->{key} } = $ix->search( $search, $conf->{exact_match} ); } } 1; __END__