17 |
use Search::Estraier; |
use Search::Estraier; |
18 |
|
|
19 |
# create and configure node |
# create and configure node |
20 |
my $node = new Search::Estraier::Node; |
my $node = new Search::Estraier::Node( |
21 |
$node->set_url("http://localhost:1978/node/test"); |
url => 'http://localhost:1978/node/test', |
22 |
$node->set_auth("admin","admin"); |
user => 'admin', |
23 |
|
passwd => 'admin' |
24 |
|
); |
25 |
|
|
26 |
# create document |
# create document |
27 |
my $doc = new Search::Estraier::Document; |
my $doc = new Search::Estraier::Document; |
34 |
$doc->add_text("Somewhere over the rainbow. Way up high."); |
$doc->add_text("Somewhere over the rainbow. Way up high."); |
35 |
$doc->add_text("There's a land that I heard of once in a lullaby."); |
$doc->add_text("There's a land that I heard of once in a lullaby."); |
36 |
|
|
37 |
die "error: ", $node->status,"\n" unless ($node->put_doc($doc)); |
die "error: ", $node->status,"\n" unless (eval { $node->put_doc($doc) }); |
38 |
|
|
39 |
=head2 Simple searcher |
=head2 Simple searcher |
40 |
|
|
41 |
use Search::Estraier; |
use Search::Estraier; |
42 |
|
|
43 |
# create and configure node |
# create and configure node |
44 |
my $node = new Search::Estraier::Node; |
my $node = new Search::Estraier::Node( |
45 |
$node->set_url("http://localhost:1978/node/test"); |
url => 'http://localhost:1978/node/test', |
46 |
$node->set_auth("admin","admin"); |
user => 'admin', |
47 |
|
passwd => 'admin', |
48 |
|
croak_on_error => 1, |
49 |
|
); |
50 |
|
|
51 |
# create condition |
# create condition |
52 |
my $cond = new Search::Estraier::Condition; |
my $cond = new Search::Estraier::Condition; |
55 |
$cond->set_phrase("rainbow AND lullaby"); |
$cond->set_phrase("rainbow AND lullaby"); |
56 |
|
|
57 |
my $nres = $node->search($cond, 0); |
my $nres = $node->search($cond, 0); |
|
print "Got ", $nres->hits, " results\n"; |
|
58 |
|
|
59 |
if (defined($nres)) { |
if (defined($nres)) { |
60 |
|
print "Got ", $nres->hits, " results\n"; |
61 |
|
|
62 |
# for each document in results |
# for each document in results |
63 |
for my $i ( 0 ... $nres->doc_num - 1 ) { |
for my $i ( 0 ... $nres->doc_num - 1 ) { |
64 |
# get result document |
# get result document |