SWISH::Prog::Aggregator::Object - index Perl objects with Swish-e
my $aggregator = SWISH::Prog::Aggregator::Object->new( methods => [qw( foo bar something something_else )], class => 'MyClass', title => 'mytitle', url => 'myurl', modtime => 'mylastmod' indexer => SWISH::Prog::Indexer::Native->new, ); my $data = my_func_for_fetching_data(); # $data is either iterator or arrayref of objects $aggregator->indexer->start; $aggregator->crawl( $data ); $aggregator->indexer->finish;
SWISH::Prog::Aggregator::Object is designed for providing full-text search for your Perl objects with Swish-e.
Since SWISH::Prog::Aggregator::Object inherits from SWISH::Prog::Aggregator, read that documentation first. Any overridden methods are documented here.
If it seems odd at first to think of indexing objects, consider the advantages:
Particularly for scalar method values, time for sorting objects by method value is greatly decreased thanks to Swish-e's pre-sorted properties.
If you use SWISH::API::Object, you can get a Storable-like freeze/thaw effect with SWISH::Prog::Aggregator::Object.
If some methods in your objects take a long while to calculate values, but don't change often, you can use Swish-e to cache those values, similar to the Cache::* modules, but in a portable, fast index.
Create new aggregator object.
opts may include:
The methods param takes an array ref of method names. Each method name will be called on each object in crawl(). Each method name will also be stored as a PropertyName in the Swish-e index, unless you explicitly create a SWISH::Prog::Config object that that defines your PropertyNames.
The name of the class each object belongs to. The class value will be stored in the index itself for later use with SWISH::API::Object (or for your own amusement).
If not specified, the first object crawl()ed will be tested with the blessed() function from Scalar::Util.
Which method to use as the swishtitle value. Defaults to title.
title
Which method to use as the swishdocpath value. Defaults to url.
url
Which method to use as the swishlastmodified value. Defaults to Perl built-in time().
Which format to use in serialize(). Default is json. You can also use yaml. If you don't like either of those, subclass SWISH::Prog::Aggregator::Object and override serialize() to provide your own format.
json
yaml
Initialize object. This overrides SWISH::Prog::Aggregator init() base method.
Index your objects.
data should either be an array ref of objects, or an iterator object with a next method. If data is an iterator, it will be used like:
next
while( my $object = $data->next ) { $aggregator->method_to_index( $object ); }
Returns number of objects indexed.
Returns a doc_class() instance representing object.
Returns a serialized (stringified) version of the return value of method_name. If the return value is already a scalar string (i.e., if ref() returns false) then the return value is returned untouched. Otherwise, the return value is serialized with either JSON or YAML, depending on how you configured serial_format in new().
serial_format
If you subclass SWISH::Prog::Aggregator::Object, then you can (of course) return whatever serialized format you prefer.
SWISH::Prog, YAML::Syck, JSON::Syck
Peter Karman, <perl@peknet.com>
Please report any bugs or feature requests to bug-swish-prog at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SWISH-Prog. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-swish-prog at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc SWISH::Prog
You can also look for information at:
Mailing list
http://lists.swish-e.org/listinfo/users
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=SWISH-Prog
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/SWISH-Prog
CPAN Ratings
http://cpanratings.perl.org/d/SWISH-Prog
Search CPAN
http://search.cpan.org/dist/SWISH-Prog/
Copyright 2008-2009 by Peter Karman
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
http://swish-e.org/
To install SWISH::Prog, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SWISH::Prog
CPAN shell
perl -MCPAN -e shell install SWISH::Prog
For more information on module installation, please visit the detailed CPAN module installation guide.