35 |
user => 'admin', |
user => 'admin', |
36 |
passwd => 'admin', |
passwd => 'admin', |
37 |
encoding => 'iso-8859-2', |
encoding => 'iso-8859-2', |
38 |
log => $Log::Log4Perl->log_object, |
log => $Log::Log4perl->log_object, |
39 |
); |
); |
40 |
|
|
41 |
Options are: |
Options are: |
60 |
(and it probably is). This encoding will be converted to C<UTF-8> for |
(and it probably is). This encoding will be converted to C<UTF-8> for |
61 |
Hyper Estraier. |
Hyper Estraier. |
62 |
|
|
63 |
|
=item log |
64 |
|
|
65 |
|
L<Log::Log4perl> object or equivalent (C<< $c->log >> can be used in |
66 |
|
L<Catalyst> and there is support for it). |
67 |
|
|
68 |
=back |
=back |
69 |
|
|
70 |
=cut |
=cut |
88 |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
my $encoding = $self->{'encoding'} || 'ISO-8859-2'; |
89 |
$log->info("using encoding $encoding"); |
$log->info("using encoding $encoding"); |
90 |
|
|
91 |
$self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or |
$self->{'iconv'} = new Text::Iconv('UTF-8', $encoding) or |
92 |
$log->die("can't create conversion from $encoding to UTF-8"); |
$log->die("can't create conversion from UTF-8 to $encoding"); |
93 |
|
|
94 |
$self ? return $self : return undef; |
$self ? return $self : return undef; |
95 |
} |
} |
99 |
|
|
100 |
Locate items in index |
Locate items in index |
101 |
|
|
102 |
$est->search( |
my @results = $est->search( |
103 |
query => 'name of book or novel', |
query => 'name of book or novel', |
104 |
attr => [ qw/PersonalName Title/ ], |
attr => qw/PersonalName TitleProper/, |
105 |
); |
); |
106 |
|
|
107 |
|
Results are returned as hash array with keys named by attributes |
108 |
|
|
109 |
=cut |
=cut |
110 |
|
|
111 |
sub search { |
sub search { |
117 |
|
|
118 |
$log->logconfess('need db in object') unless ($self->{'db'}); |
$log->logconfess('need db in object') unless ($self->{'db'}); |
119 |
$log->logconfess('need attr') unless ($args->{'attr'}); |
$log->logconfess('need attr') unless ($args->{'attr'}); |
120 |
|
|
121 |
$log->logconfess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY'); |
$log->logconfess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY'); |
122 |
|
|
123 |
# my $database = $self->{'database'} || $log->logconfess('no database in $self'); |
my $q = $args->{'query'}; |
|
# foreach my $p (qw/id ds type/) { |
|
|
# $log->logconfess("need $p") unless ($args->{$p}); |
|
|
# } |
|
124 |
|
|
125 |
my $cond = HyperEstraier::Condition->new(); |
my $cond = HyperEstraier::Condition->new(); |
126 |
# $cond->add_attr("filepath ISTRINC $q"); |
# $cond->add_attr("filepath ISTRINC $q"); |
127 |
|
|
128 |
$cond->set_phrase( $args->{'query'} ) if ($args->{'query'}); |
$cond->set_phrase( $self->{'iconv'}->convert( $q ) ) if ($q); |
129 |
$cond->set_max( $args->{'max'} ) if ($args->{'max'}); |
$cond->set_max( $args->{'max'} ) if ($args->{'max'}); |
130 |
# $cond->set_options( $HyperEstraier::Condition::SURE ); |
# $cond->set_options( $HyperEstraier::Condition::SURE ); |
131 |
# $cond->set_order( 'NUMD' ); |
# $cond->set_order( 'NUMD' ); |
134 |
$log->die("can't search for ", sub { Dumper( $args ) }); |
$log->die("can't search for ", sub { Dumper( $args ) }); |
135 |
|
|
136 |
my $hits = $result->doc_num; |
my $hits = $result->doc_num; |
137 |
$log->debug("found $hits hits"); |
$log->debug("found $hits hits for '$q'"); |
|
|
|
|
my @attrs = $args->{'attr'} || $self->confess("need attr"); |
|
138 |
|
|
139 |
my @results; |
my @results; |
140 |
|
|
141 |
for my $i ( 0 .. $hits ) { |
for my $i ( 0 .. ( $hits - 1 ) ) { |
142 |
|
|
143 |
$log->debug("get_doc($i)"); |
#$log->debug("get_doc($i)"); |
144 |
my $doc = $result->get_doc( $i ); |
my $doc = $result->get_doc( $i ); |
145 |
if (! $doc) { |
if (! $doc) { |
146 |
$log->warn("can't find result $i"); |
$log->warn("can't find result $i"); |
149 |
|
|
150 |
my $hash; |
my $hash; |
151 |
|
|
152 |
foreach my $attr (@attrs) { |
foreach my $attr (@{ $args->{'attr'} }) { |
153 |
my $val = $doc->attr( $attr ); |
my $val = $doc->attr( $attr ); |
154 |
$log->debug("attr $attr = ", $val || 'undef'); |
#$log->debug("attr $attr = ", $val || 'undef'); |
155 |
$hash->{$attr} = $val if (defined($val)); |
$hash->{$attr} = $self->{'iconv'}->convert( $val ) if (defined($val)); |
156 |
} |
} |
157 |
|
|
158 |
if ($hash) { |
if ($hash) { |