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.
plugins
plugins => [ 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:
@_
$t, $q, $conf
$t
$q
$conf
dir
dir => '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).
new()
index_files
index.pl
obj_args
obj_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).
writeMode
add
remove
[]
cell
cell => '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
key
d
key => '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
search_indexer
$t->{d}{search_indexer}
exact_match
exact_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
search()
+
0
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 => [ 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
positions
remove()
search
search => '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.
$t->{ <cell> }{ <key> }
<cell>
<key>
App::ZofCMS, Search::Indexer
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS-PluginBundle-Naughty
To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS-PluginBundle-Naughty/issues
If you can't access GitHub, you can email your request to bug-App-ZofCMS-PluginBundle-Naughty at rt.cpan.org
bug-App-ZofCMS-PluginBundle-Naughty at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.
LICENSE
To install App::ZofCMS::PluginBundle::Naughty, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::ZofCMS::PluginBundle::Naughty
CPAN shell
perl -MCPAN -e shell install App::ZofCMS::PluginBundle::Naughty
For more information on module installation, please visit the detailed CPAN module installation guide.