The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SWISH::Prog::Aggregator::Object - index Perl objects with Swish-e

SYNOPSIS

    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;

DESCRIPTION

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:

sorting

Particularly for scalar method values, time for sorting objects by method value is greatly decreased thanks to Swish-e's pre-sorted properties.

SWISH::API::Object integration

If you use SWISH::API::Object, you can get a Storable-like freeze/thaw effect with SWISH::Prog::Aggregator::Object.

caching

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.

METHODS

new( opts )

Create new aggregator object.

opts may include:

methods

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.

class

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.

title

Which method to use as the swishtitle value. Defaults to title.

url

Which method to use as the swishdocpath value. Defaults to url.

modtime

Which method to use as the swishlastmodified value. Defaults to Perl built-in time().

serial_format

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.

init

Initialize object. This overrides SWISH::Prog::Aggregator init() base method.

crawl( data )

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:

 while( my $object = $data->next )
 {
     $aggregator->method_to_index( $object );
 }
 

Returns number of objects indexed.

get_doc( object )

Returns a doc_class() instance representing object.

serialize( object, method_name )

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().

If you subclass SWISH::Prog::Aggregator::Object, then you can (of course) return whatever serialized format you prefer.

REQUIREMENTS

SWISH::Prog, YAML::Syck, JSON::Syck

AUTHOR

Peter Karman, <perl@peknet.com>

BUGS

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.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc SWISH::Prog

You can also look for information at:

COPYRIGHT AND LICENSE

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.

SEE ALSO

http://swish-e.org/