File: KinoSearch1.pm

package info (click to toggle)
libkinosearch1-perl 1.01-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, stretch
  • size: 1,568 kB
  • ctags: 1,210
  • sloc: perl: 6,805; java: 168; makefile: 3
file content (280 lines) | stat: -rw-r--r-- 6,904 bytes parent folder | download | duplicates (3)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package KinoSearch1;
use strict;
use warnings;

use 5.008003;

our $VERSION = '1.01';

use constant K_DEBUG => 0;

use XSLoader;
# This loads a large number of disparate subs.
XSLoader::load( 'KinoSearch1', $VERSION );

use base qw( Exporter );
our @EXPORT_OK = qw( K_DEBUG kdump );

sub kdump {
    require Data::Dumper;
    my $kdumper = Data::Dumper->new( [@_] );
    $kdumper->Sortkeys( sub { return [ sort keys %{ $_[0] } ] } );
    $kdumper->Indent(1);
    warn $kdumper->Dump;
}

1;

__END__

__XS__

#include "limits.h"

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#define NEED_newRV_noinc_GLOBAL
#include "ppport.h"

MODULE = KinoSearch1    PACKAGE = KinoSearch1

PROTOTYPES: disable

BOOT:
    items = 0;

=for comment
Return 1 if memory debugging is enabled.  See KinoSearch1::Util::MemManager.

=cut

IV
memory_debugging_enabled()
CODE:
    RETVAL = KINO_MEM_LEAK_DEBUG;
OUTPUT:
    RETVAL

__POD__

=head1 NAME

KinoSearch1 - search engine library

=head1 VERSION

1.01

=head1 STABLE FORK

KinoSearch1 is a fork of L<KinoSearch> version 0.165 intended to provide
stability and backwards compatibility.  For the latest features, see the main
branch.

=head1 SYNOPSIS

First, write an application to build an inverted index, or "invindex", from
your document collection.

    use KinoSearch1::InvIndexer;
    use KinoSearch1::Analysis::PolyAnalyzer;
    
    my $analyzer
        = KinoSearch1::Analysis::PolyAnalyzer->new( language => 'en' );
    
    my $invindexer = KinoSearch1::InvIndexer->new(
        invindex => '/path/to/invindex',
        create   => 1,
        analyzer => $analyzer,
    );
    
    $invindexer->spec_field( 
        name  => 'title',
        boost => 3,
    );
    $invindexer->spec_field( name => 'bodytext' );
    
    while ( my ( $title, $bodytext ) = each %source_documents ) {
        my $doc = $invindexer->new_doc;
    
        $doc->set_value( title    => $title );
        $doc->set_value( bodytext => $bodytext );
    
        $invindexer->add_doc($doc);
    }
    
    $invindexer->finish;

Then, write a second application to search the invindex:

    use KinoSearch1::Searcher;
    use KinoSearch1::Analysis::PolyAnalyzer;
    
    my $analyzer
        = KinoSearch1::Analysis::PolyAnalyzer->new( language => 'en' );
    
    my $searcher = KinoSearch1::Searcher->new(
        invindex => '/path/to/invindex',
        analyzer => $analyzer,
    );
    
    my $hits = $searcher->search( query => "foo bar" );
    while ( my $hit = $hits->fetch_hit_hashref ) {
        print "$hit->{title}\n";
    }

=head1 DESCRIPTION

KinoSearch1 is a loose port of the Java search engine library Apache Lucene,
written in Perl and C. The archetypal application is website search, but it
can be put to many different uses.

=head2 Features

=over

=item *

Extremely fast and scalable - can handle millions of documents

=item *

Incremental indexing (addition/deletion of documents to/from an existing
index).

=item *

Full support for 12 Indo-European languages.

=item *

Support for boolean operators AND, OR, and AND NOT; parenthetical groupings,
and prepended +plus and -minus

=item *

Algorithmic selection of relevant excerpts and highlighting of search terms
within excerpts

=item *

Highly customizable query and indexing APIs

=item *

Phrase matching

=item *

Stemming

=item *

Stoplists

=back

=head2 Getting Started

KinoSearch1 has many, many classes, but you only need to get acquainted with
three to start with:

=over 

=item *

L<KinoSearch1::InvIndexer|KinoSearch1::InvIndexer>

=item *

L<KinoSearch1::Searcher|KinoSearch1::Searcher>

=item *

L<KinoSearch1::Analysis::PolyAnalyzer|KinoSearch1::Analysis::PolyAnalyzer>

=back

Probably the quickest way to get something up and running is to cut and paste
the sample applications out of
L<KinoSearch1::Docs::Tutorial|KinoSearch1::Docs::Tutorial> and adapt them for
your purposes.  

=head1 SEE ALSO 

The actively developed main branch, L<KinoSearch>.

The KinoSearch homepage, where you'll find links to the mailing list and so
on, is L<http://www.rectangular.com/kinosearch>.

The Lucene homepage is L<http://lucene.apache.org>.

L<KinoSearch1::Docs::FileFormat|KinoSearch1::Docs::FileFormat>, for an overview
of the invindex file format.

=head1 History 

Search::Kinosearch 0.02x, no longer supported, is this suite's forerunner.
L<Plucene|Plucene> is a pure-Perl port of Lucene 1.3. KinoSearch is a
from-scratch project which attempts to draws on the lessons of both. The API
is not compatible with either.

KinoSearch is named for Kino, the main character in John Steinbeck's novella,
"The Pearl".

=head1 SUPPORT

Please direct support questions to the KinoSearch mailing list: subscription
information at L<http://www.rectangular.com/kinosearch>.

=head1 BUGS

UTF-8 scalars are not indexed properly.  This is fixed in KinoSearch 0.3x, but
cannot be fixed in KinoSearch1 without breaking index compatibility with
KinoSearch 0.165 from which KinoSearch1 was forked.

Not thread-safe.

Indexing crashes reliably on Solaris 2.9 or other systems which are fussy
about pointer alignment.

Please report any other bugs or feature requests to
C<bug-kinosearch1@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=KinoSearch1>.

=head1 COPYRIGHT & LICENSE

Copyright 2005-2010 Marvin Humphrey

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

Terms of usage for Apache Lucene, from which portions of KinoSearch1 are
derived, are spelled out in the Apache License: see the file
"ApacheLicense2.0.txt".

=head1 DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE
SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE,
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO
LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER
SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

=cut