NAME
Apache::Wyrd::Services::MySQLIndex - MySQL version of Index
SYNOPSIS
sub new {
my ($class) = @_;
my $dbh = DBI->connect('DBI:mysql:dbname', 'username', 'password');
my $init = {
dbh => $dbh,
debug => 0,
attributes => [qw(doctype section parent)],
maps => [qw(tags children)],
};
return &Apache::Wyrd::Site::MySQLIndex::new($class, $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};
}
DESCRIPTION
This is a MySQL-backed version of Apache::Wyrd::Services::Index
, and in most ways behaves exactly the same way, using the same methods. Consequently, only the differences are documented here.
METHODS
(format: (returns) name (arguments after self))
- (Apache::Wyrd::Services::Index)
new
(hashref) -
Create a new MySQLIndex object. Unlike the BDB-backed version, MySQLIndex is not (yet) capable of auto-creating the database backend. In this backend, tables for each indexed object must be made as well as a separate table for every reverse index, including the default "word" map which stores the data for the word search. An example table creation script for the instance under synopsis is as follows:
drop table if exists _wyrd_index; create table _wyrd_index ( id integer not null auto_increment primary key, name varchar(255) unique, timestamp long, digest char(40), data blob, wordcount integer, title text, keywords text, description text, doctype text, section text, parent text, ) ENGINE=MyISAM; drop table if exists _wyrd_index_word; create table _wyrd_index_word ( item varchar(255) not null, id integer, tally integer ) ENGINE=MyISAM; create index id on _wyrd_index_data (id); create index item on _wyrd_index_data (item); drop table if exists _wyrd_index_tags; create table _wyrd_index_tags like _wyrd_index_data; drop table if exists _wyrd_index_children; create table _wyrd_index_children like _wyrd_index_data;
Like the BDB version, the
new
method is initialized with a hashref. Important keys for this hashref:- dbd
-
A DBI::mysql object reference connected to the database where the
- strict
-
Die on errors. Default 1 (yes).
- quiet
-
If not strict, be quiet in the error log about problems. Use at your own risk.
- attributes
-
Arrayref of attributes other than the default to use. For every attribute foo, an
index_foo
method should be implemented by the object being indexed. The value returned by this method will be stored under the attribute foo. - maps
-
Arrayref of which attributes to treat as maps. Any attribute that is a map must also be included in the list of attributes.
- (hashref)
entry_by_name
(scalar) -
Given the value of an name attribute, returns a hashref of all the regular attributes stored for a given entry.
- (array)
search
(scalar, [scalar]) -
Alias for word_search. Required by
Apache::Wyrd::Services::SearchParser
.
AUTHOR
Barry King <wyrd@nospam.wyrdwright.com>
SEE ALSO
- Apache::Wyrd
-
General-purpose HTML-embeddable perl object
- Apache::Wyrd::Services::Index
-
BDB-backed base class to this class
- Apache::Wyrd::Interfaces::Indexable
-
Methods to be implemented by any item that wants to be indexed.
- Apache::Wyrd::Services::SearchParser
-
Parser for handling logical searches (AND/OR/NOT/DIFF).
LICENSE
Copyright 2002-2007 Wyrdwright, Inc. and licensed under the GNU GPL.
See LICENSE under the documentation for Apache::Wyrd
.