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->crawl( $data );


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.

SWISH::API::Object integration

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.


new( opts )

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.


Which method to use as the swishdocpath value. Defaults to 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.


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.


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


Peter Karman, <>


Please report any bugs or feature requests to bug-swish-prog at, or through the web interface at 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 SWISH::Prog

You can also look for information at:


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.