13 |
|
|
14 |
=head1 VERSION |
=head1 VERSION |
15 |
|
|
16 |
Version 0.01 |
Version 0.02 |
17 |
|
|
18 |
=cut |
=cut |
19 |
|
|
20 |
our $VERSION = '0.01'; |
our $VERSION = '0.02'; |
21 |
|
|
22 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
23 |
|
|
100 |
Locate items in index |
Locate items in index |
101 |
|
|
102 |
my @results = $est->search( |
my @results = $est->search( |
103 |
query => 'name of book or novel', |
phrase => 'name of book or novel', |
104 |
attr => qw/PersonalName TitleProper/, |
add_attr => [ |
105 |
|
"filepath ISTRINC $q", |
106 |
|
"size NUMGT 100", |
107 |
|
], |
108 |
|
get_attr => qw/PersonalName TitleProper/, |
109 |
|
order => 'NUMD', |
110 |
|
max => 100, |
111 |
|
options => $HyperEstraier::Condition::SURE, |
112 |
); |
); |
113 |
|
|
114 |
|
Options are close match to Hyper Estraier API, except C<get_attr> which defines |
115 |
|
attributes which will be returned in hash for each record. |
116 |
|
|
117 |
Results are returned as hash array with keys named by attributes |
Results are returned as hash array with keys named by attributes |
118 |
|
|
119 |
=cut |
=cut |
125 |
|
|
126 |
my $log = $self->_get_logger; |
my $log = $self->_get_logger; |
127 |
|
|
128 |
$self->confess('need db in object') unless ($self->{'db'}); |
#$log->debug( 'search args: ' . Dumper($args) ); |
|
$self->confess('need attr') unless ($args->{'attr'}); |
|
129 |
|
|
130 |
$self->confess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY'); |
$self->confess('need db in object') unless ($self->{db}); |
131 |
|
$self->confess('need get_attr') unless ($args->{get_attr}); |
132 |
|
|
133 |
my $q = $args->{'query'}; |
$self->confess("need get_attr as array not " . ref($args->{get_attr}) ) unless (ref($args->{get_attr}) eq 'ARRAY'); |
134 |
|
|
135 |
my $cond = HyperEstraier::Condition->new(); |
my $q = $args->{phrase}; |
|
# $cond->add_attr("filepath ISTRINC $q"); |
|
136 |
|
|
137 |
$cond->set_phrase( $self->{'iconv'}->convert( $q ) ) if ($q); |
$log->debug("args: " . Dumper( $args )); |
138 |
$cond->set_max( $args->{'max'} ) if ($args->{'max'}); |
|
139 |
# $cond->set_options( $HyperEstraier::Condition::SURE ); |
my $cond = HyperEstraier::Condition->new(); |
140 |
# $cond->set_order( 'NUMD' ); |
if ( ref($args->{add_attr}) eq 'ARRAY' ) { |
141 |
|
$log->debug("adding search attributes: " . join(", ", @{ $args->{add_attr} }) ); |
142 |
|
map { |
143 |
|
$cond->add_attr( $self->{iconv}->convert( $_ ) ); |
144 |
|
$log->debug(" + $_"); |
145 |
|
} @{ $args->{add_attr} }; |
146 |
|
}; |
147 |
|
|
148 |
|
$cond->set_phrase( $self->{iconv}->convert($q) ) if ($q); |
149 |
|
$cond->set_max( $args->{max} ) if ($args->{max}); |
150 |
|
$cond->set_options( $args->{options} ) if ($args->{options}); |
151 |
|
$cond->set_order( $args->{order} ) if ($args->{order}); |
152 |
|
|
153 |
my $result = $self->{'db'}->search($cond, 0) || |
my $result = $self->{db}->search($cond, 0) || |
154 |
$log->die("can't search for ", sub { Dumper( $args ) }); |
$log->die("can't search for ", sub { Dumper( $args ) }); |
155 |
|
|
156 |
my $hits = $result->doc_num; |
my $hits = $result->doc_num; |
169 |
|
|
170 |
my $hash; |
my $hash; |
171 |
|
|
172 |
foreach my $attr (@{ $args->{'attr'} }) { |
foreach my $attr (@{ $args->{get_attr} }) { |
173 |
my $val = $doc->attr( $attr ); |
my $val = $doc->attr( $attr ); |
174 |
#$log->debug("attr $attr = ", $val || 'undef'); |
#$log->debug("attr $attr = ", $val || 'undef'); |
175 |
$hash->{$attr} = $self->{'iconv'}->convert( $val ) if (defined($val)); |
$hash->{$attr} = $self->{iconv}->convert( $val ) if (defined($val)); |
176 |
} |
} |
177 |
|
|
178 |
if ($hash) { |
if ($hash) { |
181 |
|
|
182 |
} |
} |
183 |
|
|
184 |
$log->debug("results " . Dumper( \@results )); |
# $log->debug("results " . Dumper( \@results )); |
185 |
|
|
186 |
$self->confess("expected to return array") unless (wantarray); |
$self->confess("expected to return array") unless (wantarray); |
187 |
|
|