user => 'admin',
passwd => 'admin',
encoding => 'iso-8859-2',
- log => $Log::Log4Perl->log_object,
+ log => $Log::Log4perl->log_object,
);
Options are:
(and it probably is). This encoding will be converted to C<UTF-8> for
Hyper Estraier.
+=item log
+
+L<Log::Log4perl> object or equivalent (C<< $c->log >> can be used in
+L<Catalyst> and there is support for it).
+
=back
=cut
my $encoding = $self->{'encoding'} || 'ISO-8859-2';
$log->info("using encoding $encoding");
- $self->{'iconv'} = new Text::Iconv($encoding, 'UTF-8') or
- $log->die("can't create conversion from $encoding to UTF-8");
+ $self->{'iconv'} = new Text::Iconv('UTF-8', $encoding) or
+ $log->die("can't create conversion from UTF-8 to $encoding");
$self ? return $self : return undef;
}
Locate items in index
- $est->search(
+ my @results = $est->search(
query => 'name of book or novel',
- attr => [ qw/PersonalName Title/ ],
+ attr => qw/PersonalName TitleProper/,
);
+Results are returned as hash array with keys named by attributes
+
=cut
sub search {
$log->logconfess('need db in object') unless ($self->{'db'});
$log->logconfess('need attr') unless ($args->{'attr'});
- $log->logconfess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY');
-# my $database = $self->{'database'} || $log->logconfess('no database in $self');
-# foreach my $p (qw/id ds type/) {
-# $log->logconfess("need $p") unless ($args->{$p});
-# }
+ $log->logconfess("need attr as array not " . ref($args->{'attr'}) ) unless (ref($args->{'attr'}) eq 'ARRAY');
my $cond = HyperEstraier::Condition->new();
# $cond->add_attr("filepath ISTRINC $q");
my $hits = $result->doc_num;
$log->debug("found $hits hits");
- my @attrs = $args->{'attr'} || $self->confess("need attr");
-
my @results;
- for my $i ( 0 .. $hits ) {
+ for my $i ( 0 .. ( $hits - 1 ) ) {
$log->debug("get_doc($i)");
my $doc = $result->get_doc( $i );
my $hash;
- foreach my $attr (@attrs) {
+ foreach my $attr (@{ $args->{'attr'} }) {
my $val = $doc->attr( $attr );
$log->debug("attr $attr = ", $val || 'undef');
- $hash->{$attr} = $val if (defined($val));
+ $hash->{$attr} = $self->{'iconv'}->convert( $val ) if (defined($val));
}
if ($hash) {
use strict;
-use Test::More tests => 16;
+use Test::More tests => 6;
use Test::Exception;
use Cwd qw/abs_path/;
use File::Temp qw/tempdir/;
), "new");
my $query = 'ivan';
-my $max = 3;
+my $max = 10;
ok(my @res = $est->search(
query => $query,
max => $max,
- attr => [ qw/PersonalName/ ],
+ attr => [ qw/PersonalName TitleProper/ ],
), "search $query, max: $max");
-cmp_ok($#res, '==', $max, "$max hits");
+cmp_ok(($#res + 1), '==', $max, "$max hits");
diag Dumper(\@res);