This file is indexed.

/usr/share/perl5/Wiki/Toolkit/Search/SII.pm is in libwiki-toolkit-perl 0.85-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package Wiki::Toolkit::Search::SII;

use strict;
use Search::InvertedIndex;
use Carp "croak";
use base 'Wiki::Toolkit::Search::Base';

use vars qw( @ISA $VERSION );

$VERSION = 0.09;

=head1 NAME

Wiki::Toolkit::Search::SII - Search::InvertedIndex plugin for Wiki::Toolkit.

=head1 SYNOPSIS

  my $indexdb = Search::InvertedIndex::DB::Mysql->new( ... );
  my $search = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb );
  my %wombat_nodes = $search->search_nodes("wombat");

Provides search-related methods for L<Wiki::Toolkit>.

See also L<Wiki::Toolkit::Search::Base>, for methods not documented here.

=cut

=head1 METHODS

=over 4

=item B<new>

  # EITHER

  my $indexdb = Search::InvertedIndex::DB::Mysql->new(
                   -db_name    => $dbname,
                   -username   => $dbuser,
                   -password   => $dbpass,
           -hostname   => '',
                   -table_name => 'siindex',
                   -lock_mode  => 'EX' );

  # OR

  my $indexdb = Search::InvertedIndex::DB::DB_File_SplitHash->new(
                   -map_name  => "/home/wiki/indexes.db",
                   -lock_mode => "EX" );

  # THEN

  my $search = Wiki::Toolkit::Search::SII->new( indexdb => $indexdb );

Takes only one parameter, which is mandatory. C<indexdb> must be a
C<Search::InvertedIndex::DB::*> object.

=cut

sub _init {
    my ($self, %args) = @_;
    my $indexdb = $args{indexdb};

    my $map = Search::InvertedIndex->new( -database => $indexdb )
        or croak "Couldn't set up Search::InvertedIndex map";
    $map->add_group( -group => "nodes" );
    $map->add_group( -group => "fuzzy_titles" );

    $self->{_map}  = $map;

    return $self;
}

sub _do_search {
    my ($self, $and_or, $terms) = @_;

    # Create a leaf for each search term.
    my @leaves;
    foreach my $term ( @$terms ) {
        my $leaf = Search::InvertedIndex::Query::Leaf->new(-key   => $term,
                                                           -group => "nodes" );
        push @leaves, $leaf;
    }

    # Collate the leaves.
    my $query = Search::InvertedIndex::Query->new( -logic => $and_or,
                                                   -leafs => \@leaves );

    # Perform the search and extract the results.
    my $result = $self->{_map}->search( -query => $query );

    my $num_results = $result->number_of_index_entries || 0;
    my %results;
    for my $i ( 1 .. $num_results ) {
        my ($index, $data, $ranking) = $result->entry( -number => $i - 1 );
        $results{$index} = $ranking;
    }
    return %results;
}

sub _fuzzy_match {
    my ($self, $string, $canonical) = @_;
    my $leaf = Search::InvertedIndex::Query::Leaf->new(
        -key   => $canonical,
        -group => "fuzzy_titles" );

    my $query = Search::InvertedIndex::Query->new( -leafs => [ $leaf ] );

    my $result = $self->{_map}->search( -query => $query );

    my $num_results = $result->number_of_index_entries || 0;
    my %results;
    for my $i ( 1 .. $num_results ) {
        my ($index, $data) = $result->entry( -number => $i - 1 );
        $results{$data} = $data eq $string ? 2 : 1;
    }
    return %results;
}

sub _index_node {
    my ($self, $node, $content, $keys) = @_;
    my $update = Search::InvertedIndex::Update->new(
        -group => "nodes",
        -index => $node,
        -data  => $content,
        -keys => { map { $_ => 1 } @$keys }
    );
    $self->{_map}->update( -update => $update );
}

sub _index_fuzzy {
    my ($self, $node, $canonical) = @_;
    my $update = Search::InvertedIndex::Update->new(
        -group => "fuzzy_titles",
        -index => $node . "_fuzzy_title",
        -data  => $node,
        -keys  => { $canonical => 1 }
    );
    $self->{_map}->update( -update => $update );
}

sub _delete_node {
    my ($self, $node) = @_;
    $self->{_map}->remove_index_from_all({ -index => $node });
}

sub supports_phrase_searches { return 0; }
sub supports_fuzzy_searches  { return 1; }

=back

=head1 SEE ALSO

L<Wiki::Toolkit>, L<Wiki::Toolkit::Search::Base>.

=cut

1;