NAME
SWISH::Prog::Index - handle Swish-e indexing
SYNOPSIS
use SWISH::Prog::Index
my $indexer = SWISH::Prog::Index->new(
format => 'native2' || 'btree2',
config => SWISH::Prog::Config->new,
exe => 'path/to/swish-e',
verbose => 0|1|2|3,
warnings => 0|1|2|3,
name => 'path/to/myindex'
);
$indexer->run;
print "index files: $_" for $indexer->files;
# or from the command line
DirTree.pl some/path | perl -MSWISH::Prog::Index -e go
DESCRIPTION
SWISH::Prog::Index performs Swish-e indexing. For version 2.x of Swish-e this is simply a convenience wrapper around the swish-e binary executable.
FUNCTIONS
go
Magic method to run the indexer with all defaults. See SYNOPSIS for an example.
You might object that the perl line is harder to remember than 'swish-e -v0 -W0 -S prog -i stdin' and it takes 0.1 second longer to run.
True enough. But go() was easy to code in two lines, so I did. And it requires one less keystroke. Laziness is a virtue!
go() is the only export of this module.
METHODS
new
Create indexer object. All the following parameters are also accessor methods.
- name
-
The name of the index. Should be a file path.
- config
-
A SWISH::Prog::Config object.
- exe
-
The path to the
swish-e
executable. If empty, will just look in $ENV{PATH}. - verbose
-
Takes same args as
swish-e -v
option. - warnings
-
Takes same args as
swish-e -W
option. - format
-
Tell the indexer what kind of index to expect. Options are
native2
(default) orbtree
(for the experimental incremental feature in version 2.4).The
format
param API is subject to change as Swish3 is developed.
fh
Get or set the open() filehandle for the swish-e process. CAUTION: don't set unless you know what you're doing.
You can print() to the filehandle using the SWISH::Prog index() method. Or do it directly like:
print { $indexer->fh } "your headers and body here";
The filehandle is close()'d by the DESTROY magic method in this class. So when $indexer goes undef, the indexing process is closed automatically.
rm
Remove the index (all the associated index files). Useful if creating a temp index for merging, etc.
Returns 0 and carps if there was a problem unlink()ing any file. Returns 1 otherwise.
mv( new_name )
Rename the index. Useful if creating temp indexes, etc.
Returns 1 on success, 0 on failure.
files
Returns a list of all the associated files for the index.
run( [cmd] )
Start the indexer on its merry way. Stores the filehandle with the fh method for later access via SWISH::Prog or other methods TBD.
Returns the $indexer object.
You likely don't want to pass cmd in but let run() construct it for you.
merge( @list_of_indexes )
merge() will merge @list_of_indexes together with the index named in the calling object.
Returns the $indexer object on success, 0 on failure.
add( swish_prog_doc_object )
add() will merge swish_prog_doc_object with the index named in the calling object. If the existing index uses the btree2 format (incremental mode), that API will be used. Otherwise, swish_prog_doc_object is indexed as a temporary index and then merged.
Returns $indexer object on success, 0 on failure.
AUTHOR
Peter Karman, <perl@peknet.com>
COPYRIGHT AND LICENSE
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.