| 1 | package Wiki::Toolkit::Setup::SII; |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | |
|---|
| 5 | use vars qw( $VERSION ); |
|---|
| 6 | $VERSION = '0.03'; |
|---|
| 7 | |
|---|
| 8 | use DBI; |
|---|
| 9 | use Search::InvertedIndex; |
|---|
| 10 | use Wiki::Toolkit::Search::SII; |
|---|
| 11 | use Carp; |
|---|
| 12 | |
|---|
| 13 | =head1 NAME |
|---|
| 14 | |
|---|
| 15 | Wiki::Toolkit::Setup::SII - Set up Search::InvertedIndex indexes for Wiki::Toolkit |
|---|
| 16 | |
|---|
| 17 | =head1 SYNOPSIS |
|---|
| 18 | |
|---|
| 19 | use Wiki::Toolkit::Setup::SII; |
|---|
| 20 | my $indexdb = Search::InvertedIndex::DB::Mysql->new( |
|---|
| 21 | -db_name => $dbname, |
|---|
| 22 | -username => $dbuser, |
|---|
| 23 | -password => $dbpass, |
|---|
| 24 | -hostname => '', |
|---|
| 25 | -table_name => 'siindex', |
|---|
| 26 | -lock_mode => 'EX' ); |
|---|
| 27 | Wiki::Toolkit::Setup::SII::setup( indexdb => $indexdb ); |
|---|
| 28 | |
|---|
| 29 | =head1 DESCRIPTION |
|---|
| 30 | |
|---|
| 31 | Set up L<Search::InvertedIndex> indexes for use with L<Wiki::Toolkit.> Has |
|---|
| 32 | only one function, C<setup>, which takes one mandatory argument, |
|---|
| 33 | C<indexdb>, the C<Search::InvertedIndex::DB::*> object to use as the |
|---|
| 34 | backend, and one optional argument, C<store>, a C<Wiki::Toolkit::Store::* |
|---|
| 35 | object> corresponding to existing data that you wish to (re-)index. |
|---|
| 36 | |
|---|
| 37 | Note that any pre-existing L<Wiki::Toolkit> indexes stored in C<indexdb> |
|---|
| 38 | will be I<cleared> by this function, so if you have existing data you |
|---|
| 39 | probably want to use the C<store> parameter to get it re-indexed. |
|---|
| 40 | |
|---|
| 41 | =cut |
|---|
| 42 | |
|---|
| 43 | sub setup { |
|---|
| 44 | my %args = @_; |
|---|
| 45 | my $indexdb = $args{indexdb}; |
|---|
| 46 | croak "Must supply indexdb" unless $indexdb; |
|---|
| 47 | |
|---|
| 48 | # Drop indexes if they already exist. |
|---|
| 49 | $indexdb->open; |
|---|
| 50 | $indexdb->clear; |
|---|
| 51 | $indexdb->close; |
|---|
| 52 | |
|---|
| 53 | # If we've been passed a store, index all its data. |
|---|
| 54 | my $store = $args{store}; |
|---|
| 55 | if ( $store ) { |
|---|
| 56 | my @nodes = $store->list_all_nodes; |
|---|
| 57 | my $search = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb ); |
|---|
| 58 | foreach my $node ( @nodes ) { |
|---|
| 59 | my $content = $store->retrieve_node( $node ); |
|---|
| 60 | $search->index_node( $node, $content ); |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | =head1 AUTHOR |
|---|
| 66 | |
|---|
| 67 | Kake Pugh (kake@earth.li). |
|---|
| 68 | |
|---|
| 69 | =head1 COPYRIGHT |
|---|
| 70 | |
|---|
| 71 | Copyright (C) 2002 Kake Pugh. All Rights Reserved. |
|---|
| 72 | |
|---|
| 73 | This module is free software; you can redistribute it and/or modify it |
|---|
| 74 | under the same terms as Perl itself. |
|---|
| 75 | |
|---|
| 76 | =head1 SEE ALSO |
|---|
| 77 | |
|---|
| 78 | L<Wiki::Toolkit>, L<Wiki::Toolkit::Setup::MySQL>, L<DBIx::FullTextSearch> |
|---|
| 79 | |
|---|
| 80 | =cut |
|---|
| 81 | |
|---|
| 82 | 1; |
|---|