MyConText - Perl extension for indexing of documents in MySQL
use MyConText; use DBI; my $dbh = DBI->connect('dbi:mysql:database', 'user', 'passwd'); my $ctx = create MyConText($dbh, 'ctx_web_1'); ### my $ctx = open MyConText($dbh, 'ctx_web_1'); $ctx->index(1, 'krtek leze'); my @documents = $ctx->contains('krtek');
MyConText is a pure man's solution for indexing documents. It uses the MySQL database for basic storing of the information and provides Perl interface for indexing new documents, making changes and searching for matches.
MyConText uses a single table to store information about a collection of documents. These documents may also be stored in the database or it may be a bunch of web pages, anything. The only restriction is that these documents have to be indexed by integers.
The first thing, you have to create the table. Call create method, with the database handler $dbh and a desired name of the table as parameters. The optional third parameter is the length of the words that will be indexed, 30 by dafault. This method returns a MyConText object that you can work with:
my $ctx = create MyConText($dbh, 'ctx_web_1');
If you already have the table created, you use a method open that again returns a object:
my $ctx = open MyConText($dbh, 'ctx_web_1');
Once you have the object, you can tell it to index a document:
The first argument is the integer identificator of the document, the second is the text of the document. This text will be splitted into words and an information about each word occurence will be recorded.
Then, you can ask for a list of ids of documents that contain certain word:
my @documents = $ctx->contains('krtek');
(c) 1999 Jan Pazdziora, firstname.lastname@example.org