Apache::Wyrd::Services::MySQLIndex - MySQL version of Index
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}; }
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.
Apache::Wyrd::Services::Index
(format: (returns) name (arguments after self))
new
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:
A DBI::mysql object reference connected to the database where the
Die on errors. Default 1 (yes).
If not strict, be quiet in the error log about problems. Use at your own risk.
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.
index_foo
Arrayref of which attributes to treat as maps. Any attribute that is a map must also be included in the list of attributes.
entry_by_name
Given the value of an name attribute, returns a hashref of all the regular attributes stored for a given entry.
search
Alias for word_search. Required by Apache::Wyrd::Services::SearchParser.
Apache::Wyrd::Services::SearchParser
Barry King <wyrd@nospam.wyrdwright.com>
General-purpose HTML-embeddable perl object
BDB-backed base class to this class
Methods to be implemented by any item that wants to be indexed.
Parser for handling logical searches (AND/OR/NOT/DIFF).
Copyright 2002-2007 Wyrdwright, Inc. and licensed under the GNU GPL.
See LICENSE under the documentation for Apache::Wyrd.
Apache::Wyrd
To install Apache::Wyrd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache::Wyrd
CPAN shell
perl -MCPAN -e shell install Apache::Wyrd
For more information on module installation, please visit the detailed CPAN module installation guide.