|
Apache::Wyrd::Services::Index - Metadata index for word/data search engines |
Apache::Wyrd::Services::Index - Metadata index for word/data search engines
my $init = {
file => '/var/lib/Wyrd/pageindex.db',
strict => 1,
attributes => [qw(author text subjects)],
maps => [qw(subjects)]
};
my $index = Apache::Wyrd::Services::Index->new($init);
my @subject_is_foobar = $index->word_search('foobar', 'subjects');
my @pages =
$index->word_search('+musthaveword -mustnothaveword
other words to search for and add to results');
foreach my $page (@pages) {
print "title: $$page{title}, author: $$page{author};
}
my @pages = $index->parsed_search('(this AND that) OR "the other"');
foreach my $page (@pages) {
print "title: $$page{title}, author: $$page{author};
}
General purpose Index object for retrieving a variety of information on
a class of objects. The objects can have any type, but must implement
at a minimum the Apache::Wyrd::Interfaces::Indexable interface.
The information stored is broken down into attributes. The main builtin
(and not override-able) attributes are data, word, title, and
description, as well as three internal attributes of reverse,
timestamp, and digest. Additional attributes are specified via
the hashref argument to the new method (see below). There can be
only 255 total attributes.
Attributes are of two types, either regular or map, and these relate to the main index, id. A regular attribute stores information on a one-id-to-one-attribute basis, such as title or description. A map attribute provides a reverse lookup, such as words in a document, or subjects covered by documents, such as documents with the word ``foo'' in them or items classified as ``bar''. One builtin map exists, word which reverse-indexes every word of the attribute data.
The Index is meant to be used as a storage for meta-data about web pages, and in this capacity, data and word provide the exact match and word-search capacity respectively.
The internal attributes of digest and timestamp are also used to
determine whether the information for the item is fresh. It is assumed
that testing a timestamp is faster than producing a digest, and that a
digest is faster to produce than re-indexing a document, so a check to
these two criteria is made before updating an entry for a given item.
See update_entry.
The information is stored in a Berkeley DB, using the
BerkeleyDB::Btree perl module. Because of concurrence of usage
between different Apache demons in a pool of servers, it is important
that this be a reasonably current version of BerkeleyDB which supports
locking and read-during-update. This module was developed using
Berkeley DB v. 3.3-4.1 on Darwin and Linux.
Use with vast amounts of large documents is not recommended, but a
reasonably large (hundreds of 1000-word pages) web site can be indexed
and searched reasonably quickly(TM) on most cheap servers as of this
writing. All hail Moore's Law.
(format: (returns) name (arguments after self))
new (hashref)index_foo method should be implemented by the object being
indexed. The value returned by this method will be stored under the attribute
foo.
delete_index (void)update_entry (Apache::Wyrd::Interfaces::Indexable ref)index_foo for every
attribute foo in the index, storing that value under the attribute entry for
that object. The function always returns a message about the process.
update_entry will always check index_timestamp and index_digest. If the stored
value and the returned value agree on either attribute, the index will not be
updated. This behavior can be overridden by returning a true value from method
force_update.
entry_by_name (scalar)clean_html (scalar)word_search (scalar, [scalar])If a token begins with a plus sign (+), results must have the word, with a minus sign, (-) they must not. These signs can also be placed left of phrases enclosed by double quotes.
Results are returned in an array of hashrefs ranked by ``score''. The attribute ``score'' is added to the hash, meaning number of matches for that given entry. All other regular attributes of the indexable object are values of the keys of each hash returned.
The default map to use for this method is 'word'. If the optional second argument is given, that map will be used.
search (scalar, [scalar])Apache::Wyrd::Services::SearchParser.
parsed_search (scalar, [scalar])
UNKNOWN
Barry King <wyrd@nospam.wyrdwright.com>
Copyright 2002-2004 Wyrdwright, Inc. and licensed under the GNU GPL.
See LICENSE under the documentation for Apache::Wyrd.
|
Apache::Wyrd::Services::Index - Metadata index for word/data search engines |