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

NAME

XAO::DO::Data::Index - XAO Indexer storable index object

SYNOPSIS

 my $keywords=$cgi->param('keywords');
 my $cn_index=$odb->fetch('/Indexes/customer_names');
 my $sr=$cn_index->search_by_string('name',$keywords);

DESCRIPTION

XAO::DO::Data::Index is based on XAO::FS Hash object and provides wrapper methods for most useful XAO Indexer functions.

METHODS

build_structure ()

If called without arguments creates initial structure in the object required for it to function properly. Safe to call on already existing data.

Will create a certain number data fields to be then used to store specifically ordered object IDs according to get_orderings() method of the corresponding indexer. The number is taken from site's configuration '/indexer/max_orderings' parameter and defaults to 10.

Should be called from site config's build_structure() method in a way similar to this:

 $odb->fetch('/Indexes')->get_new->build_structure;

Where '/Indexes' is a container objects with class 'Data::Index'. It does not have to be named 'Indexes'.

data_structure (;$$)

Returns data structure of Index data object, can be directly used in build_structure() method.

The first optional argument is the number of fields to hold orderings. If it is not given site configuration's '/indexer/max_orderings' parameter is used, which defaults to 10.

Second parameter sets the maximum size of single keyword data chunk that lists all places where this word was found. Default is taken from '/indexer/max_kwdata_length' configuration parameter and defaults to 65000.

get_collection_object ()

A shortcut to indexer's get_collection_object method. If there is no such method, emulates it with a call to get_collection, which is usually slower (for compatibility).

get_collection ()

Simply a shortcut to indexer's get_collection() method.

indexer (;$)

Returns corresponding indexer object, its name taken from 'indexer_objname' property.

search_by_string ($)

Most widely used method - parses string into keywords and performs a search on them. Honors double quotes to mark words that have to be together in a specific order.

Returns a reference to the list of collection IDs. IDs are not checked against real collection. If index is not in sync with the content of the actual data collection IDs of objects that don't exist any more can be returned as well as irrelevant results.

Example:

 my $keywords=$cgi->param('keywords');
 my $cn_index=$odb->fetch('/Indexes/customer_names');
 my $sr=$cn_index->search_by_string('name',$keywords);

Optional third argument can refer to a hash. If it is present, the hash will be filled with some internal information. Most useful of which is the list of ignored words from the query, stored as 'ignored_words' in the hash.

Example: my %sd; my $sr=$cn_index->search_by_string('name',$keywords,\%sd); if(keys %{$sd{ignored_words}}) { print "Ignored words:\n"; foreach my $word (sort keys %{$sd{ignored_words}}) { print " * $word ($sd{ignored_words}->{$word}\n"; } }

update ($)

Updates the index with the current data. Exactly what data it is based on depends entirely on the corresponding indexer object.

With drivers that support transactions the update is wrapped into a transaction, so that index data is consistent while being updated.

AUTHORS

Copyright (c) 2003 XAO Inc.

Andrew Maltsev <am@xao.com>.

SEE ALSO

Recommended reading: XAO::Indexer, XAO::DO::Indexer::Base, XAO::FS, XAO::Web.