1Lucy::Simple(3)       User Contributed Perl Documentation      Lucy::Simple(3)
2
3
4

NAME

6       Lucy::Simple - Basic search engine.
7

SYNOPSIS

9       First, build an index of your documents.
10
11           my $index = Lucy::Simple->new(
12               path     => '/path/to/index/'
13               language => 'en',
14           );
15
16           while ( my ( $title, $content ) = each %source_docs ) {
17               $index->add_doc({
18                   title    => $title,
19                   content  => $content,
20               });
21           }
22
23       Later, search the index.
24
25           my $total_hits = $index->search(
26               query      => $query_string,
27               offset     => 0,
28               num_wanted => 10,
29           );
30
31           print "Total hits: $total_hits\n";
32           while ( my $hit = $index->next ) {
33               print "$hit->{title}\n",
34           }
35

DESCRIPTION

37       Lucy::Simple is a stripped-down interface for the Apache Lucy search
38       engine library.
39

CONSTRUCTORS

41   new
42           my $lucy = Lucy::Simple->new(
43               path     => '/path/to/index/',
44               language => 'en',
45           );
46
47       Create a Lucy::Simple object, which can be used for both indexing and
48       searching.  Both parameters "path" and "language" are required.
49
50       ·   path - Where the index directory should be located.  If no index is
51           found at the specified location, one will be created.
52
53       ·   language - The language of the documents in your collection,
54           indicated  by a two-letter ISO code.  12 languages are supported:
55
56               |-----------------------|
57               | Language   | ISO code |
58               |-----------------------|
59               | Danish     | da       |
60               | Dutch      | nl       |
61               | English    | en       |
62               | Finnish    | fi       |
63               | French     | fr       |
64               | German     | de       |
65               | Italian    | it       |
66               | Norwegian  | no       |
67               | Portuguese | pt       |
68               | Spanish    | es       |
69               | Swedish    | sv       |
70               | Russian    | ru       |
71               |-----------------------|
72

METHODS

74   add_doc
75           $lucy->add_doc({
76               location => $url,
77               title    => $title,
78               content  => $content,
79           });
80
81       Add a document to the index. The document must be supplied as a
82       hashref, with field names as keys and content as values.
83
84   search
85           my $int = $simple->search(
86               query      => $query,       # required
87               offset     => $offset,      # default: 0
88               num_wanted => $num_wanted,  # default: 10
89               sort_spec  => $sort_spec,   # default: undef
90           );
91
92       Search the index.  Returns the total number of documents which match
93       the query.  (This number is unlikely to match "num_wanted".)
94
95       ·   query - A search query string.
96
97       ·   offset - The number of most-relevant hits to discard, typically
98           used when XpagingX through hits N at a time.  Setting offset to 20
99           and num_wanted to 10 retrieves hits 21-30, assuming that 30 hits
100           can be found.
101
102       ·   num_wanted - The number of hits you would like to see after
103           "offset" is taken into account.
104
105       ·   sort_spec - A SortSpec, which will affect how results are ranked
106           and returned.
107
108   next
109           my $hit_doc = $simple->next();
110
111       Return the next hit, or undef when the iterator is exhausted.
112

INHERITANCE

114       Lucy::Simple isa Clownfish::Obj.
115
116
117
118perl v5.32.0                      2020-07-28                   Lucy::Simple(3)
Impressum