1 |
#!/usr/bin/env perl |
2 |
# simplest implementation of a node searcher |
3 |
|
4 |
use strict; |
5 |
use warnings; |
6 |
|
7 |
use HyperEstraier; |
8 |
|
9 |
# open the database |
10 |
my $node = HyperEstraier::Node->new("http://localhost:1978/node/test1"); |
11 |
$node->set_auth('admin', 'admin'); |
12 |
|
13 |
# create a search condition object |
14 |
my $cond = HyperEstraier::Condition->new(); |
15 |
|
16 |
# set the search phrase to the search condition object |
17 |
$cond->set_phrase('somewhere'); |
18 |
|
19 |
# get the result of search |
20 |
my $result = $node->search($cond, 0); |
21 |
|
22 |
print "found ", $result->doc_num, " results\n"; |
23 |
|
24 |
# for each document in result |
25 |
for my $i (0 .. $result->doc_num-1) { |
26 |
my $ndoc = $result->get_doc($i); |
27 |
# display attributes |
28 |
printf "URI: %s\n", $ndoc->attr('@uri'); |
29 |
printf "Title: %s\n", $ndoc->attr('@title'); |
30 |
|
31 |
# display the snippet text |
32 |
print $ndoc->snippet(), "\n"; |
33 |
} |