SWISH::Prog::Object - index Perl objects with Swish-e
package My::Object; use base qw( SWISH::Prog::Object ); 1; package My::Object::Doc; use base qw( SWISH::Prog::Object::Doc ); sub url_filter { my $doc = shift; my $obj = $doc->obj; $doc->url( $obj->method_I_want_as_url ); } 1; package main; use Carp; my $indexer = My::Object->new( methods => [qw( foo bar something something_else )], class => 'My::Class', title => 'mytitle', url => 'myurl', modtime => 'mylastmod' ); my $data = my_func_for_fetching_data(); # $data is either iterator or arrayref of objects $indexer->create( $data );
SWISH::Prog::Object is a SWISH::Prog subclass designed for providing full-text search for your Perl objects with Swish-e.
Since SWISH::Prog::Object inherits from SWISH::Prog, read the SWISH::Prog docs 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::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 indexer object.
NOTE: The new() method simply inherits from SWISH::Prog, so any params valid for that method() are allowed here.
The methods param takes an array ref of method names. Each method name will be called on each object in create(). Each method name will also be stored as a PropertyName in the Swish-e index.
If not specified, a simple Symbol table lookup will be done on class and all non-built-in methods will be used by default.
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, defaults to SWISH::Prog::Object::Doc::Instance.
SWISH::Prog::Object::Doc::Instance
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().
Initialize object. This overrides SWISH::Prog init() base method.
Adds the PropertyNames for each of methods. The special PropertyNamesNoStripChars config option is used so that all whitespace etc is preserved verbatim.
Each method is also configured as a MetaName. A top level MetaName using the classname value is also configured.
Index your objects.
data should either be an array ref of objects, or an iterator object with two methods: done and next. If data is an iterator, it will be used like:
done
next
until($data->done) { $indexer->deal_with( $data->next ); }
Returns number of objects indexed.
Returns object as an XML string.
Override this method if you need to alter the object data prior to being indexed.
This method is called prior to title_filter() so all object data is affected.
NOTE: This is different from the obj() method in the ::Doc subclass. This obj_filter() gets called before the Doc object is created.
Override this method if you do not provide a title param in new() or if you have no title method to call on object.
The return value of title_filter() will be used as the swishtitle for the object's virtual XML document.
swishtitle
SWISH::Prog, Data::Dump
SWISH::Prog::Object cannot index method values that are not scalars, array refs or hash refs, due to how reference values stringify with Data::Dump.
http://swish-e.org/docs/
SWISH::Prog, SWISH::API:Object
Peter Karman, <perl@peknet.com>
Thanks to Atomic Learning for supporting the development of this module.
Copyright 2006 by Peter Karman
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
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.