KSx::IndexManager - high-level invindex management interface
0.004
my $mgr = KSx::IndexManager->new({ root => '/path/to/some/dir', schema => 'My::Schema', }); my %arg = (type => "animal", id => 17); $mgr->context(\%arg); $mgr->write(\@docs); $mgr->append(\@more_docs); my $hits = $mgr->search(%search_arg); my $invindexer = $mgr->invindexer; my $searcher = $mgr->searcher;
This module is new and not completely thought out. The interface may change in incompatible ways, though I will give big alerts in the changelog when that happens. Please use it and give me feedback. Please do not use it if you want something that you can install and forget about.
In particular, the plugin interface is likely to change a great deal.
KSx::IndexManager aims to provide simple access to one or more invindexes that all share a single schema.
Functionality is intentionally simple and is basically limited to convenient wrappers around common InvIndexer and Searcher methods. Additional functionality can be added through plugins.
my $mgr = KSx::IndexManager->new(\%data);
Return a new IndexManager. Possible data keys are root, context, and schema; see those method descriptions for details.
My::Manager->add_plugins( $plugin => \%arg, $other_plugin => \%other_arg );
Instantiates one or more plugins and adds them to the manager class. See PLUGINS for details.
Arguments are a list of pairs, plugin name and hashref of arguments. See individual plugin classes for details.
Default to KinoSearch::InvIndexer and KinoSearch::Searcher, respectively. Setting these to new classes will automatically load those classes; see "set_component_class" in Class::Accessor::Grouped.
If you do not set schema_class, you will have to supply a schema argument for every object instantiation.
Accessor/mutator for the base directory for this Manager. This directory may or may not actually be an invindex, depending on the plugins loaded.
Name of the KinoSearch::Schema-derived class to use. This argument is mandatory if you have not set schema_class.
Arbitrary, application-specific data that defines the current context for index management. For example, the Partition plugin looks at the manager's context to determine which specific invindex to use.
Returns the path to the manager's invindex, based on root (and possibly context). With no plugins loaded, this is probably the same as root.
root
context
$mgr->add_docs(\%options, \@docs); $mgr->add_docs(\%options, $doc_iterator); $mgr->write(\@docs); $mgr->append(\@docs);
Add documents to an invindex. This combines invindexer creation, document addition, and invindexer finishing all in one call.
Currently the only valid option is mode, which may be one of 'clobber' or 'open'.
mode
write and append are convenient wrappers around add_docs with the 'clobber' and 'open' modes, respectively.
write
append
add_docs
The documents to be added may be passed in an arrayref or an iterator. Any object with a 'next' method will be treated as an iterator and used until exhausted.
Returns the number of objects processed.
my $doc = $mgr->to_doc($obj);
Given some object, convert it into a document suitable for passing to the invindexer's add_doc method.
The structure of the object is manager-subclass dependent. The default to_doc is to do nothing, meaning that the object should be a hashref whose keys correspond to the schema class' fields.
to_doc
You almost certainly want to override this in your manager subclass.
my $invindexer = $mgr->invindexer({ mode => $mode });
Open a new invindexer with the given mode, which may be one of 'clobber' or 'open'.
clobber and open are convenient wrappers around invindexer with the 'clobber' and 'open' modes, respectively.
clobber
open
invindexer
$mgr->lock; # do some stuff $mgr->unlock;
You should never have to use these methods.
lock and unlock open and call flock() on the file 'mgr.lock' in the manager's path. Writing to the invindex calls these methods implicitly.
lock
unlock
flock()
path
If the lockfile is already locked, lock will die.
my $searcher = $mgr->searcher; my $hits = $mgr->search(%args);
Retrieve a searcher (using searcher_class).
searcher_class
search is a shortcut for $mgr->searcher->search.
search
$mgr->searcher->search
A manager class can add any number of plugins. Plugin names are assumed to be under KSx::IndexManager::Plugin:: unless they are prepended with a '+' (+My::KSx::Plugin).
KSx::IndexManager::Plugin::
+My::KSx::Plugin
Plugins can be added multiple times, possibly with different arguments. See KSx::IndexManager::Plugin::Partition for an example.
See KSx::IndexManager::Plugin for details of what plugins can do, and see add_plugin for details of adding them.
KinoSearch
Hans Dieter Pearcey, <hdp@cpan.org>
<hdp@cpan.org>
Please report any bugs or feature requests to bug-ksx-indexmanager at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=KSx-IndexManager. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-ksx-indexmanager at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc KSx::IndexManager
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/KSx-IndexManager
CPAN Ratings
http://cpanratings.perl.org/d/KSx-IndexManager
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=KSx-IndexManager
Search CPAN
http://search.cpan.org/dist/KSx-IndexManager
Thanks to Listbox.com, who sponsored the original version of this module.
Copyright 2007 Hans Dieter Pearcey, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install KSx::IndexManager, copy and paste the appropriate command in to your terminal.
cpanm
cpanm KSx::IndexManager
CPAN shell
perl -MCPAN -e shell install KSx::IndexManager
For more information on module installation, please visit the detailed CPAN module installation guide.