1 |
dpavlin |
1 |
#!/usr/bin/env perl |
2 |
|
|
# simplest implementation of a searcher |
3 |
|
|
|
4 |
|
|
use strict; |
5 |
|
|
use Data::Dumper; |
6 |
|
|
|
7 |
|
|
use HyperEstraier; |
8 |
|
|
|
9 |
|
|
# open the database |
10 |
|
|
my $db = HyperEstraier::Database->new(); |
11 |
|
|
$db->open('casket', $HyperEstraier::ESTDBREADER); |
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 = $db->search($cond, 0); |
21 |
|
|
$result->get(0); |
22 |
|
|
|
23 |
|
|
# for each document in result |
24 |
|
|
for my $i (0..$result->size-1) { |
25 |
|
|
my $id = $result->get($i); |
26 |
|
|
my $doc = $db->get_doc($id, 0); |
27 |
|
|
# display attributes |
28 |
|
|
printf "URI: %s\n", $doc->attr('@uri'); |
29 |
|
|
printf "Title: %s\n", $doc->attr('@title'); |
30 |
|
|
|
31 |
|
|
# display the body text |
32 |
|
|
print $doc->cat_texts(), "\n"; |
33 |
|
|
} |