my @query_parts;
my @filter_parts;
foreach my $s ( @{ $search->{searches} } ) {
- my ($wh, $op, $val) = $s->{'where', 'operator', 'value'};
- my ($q_type);
+ my ($wh, $op, $val) = @{ $s }{qw(where operator value)};
+ $wh = '_any' if $wh eq 'any';
if ($op eq 'is' || $op eq '=') {
# look for something that matches completely
# note, '=' is about numerical vals. May need special handling.
$builder->build_authorities_query_compat( \@marclist, \@and_or,
\@excluding, \@operator, \@value, $authtypecode, $orderby );
-This builds a query for searching for authorities.
+This builds a query for searching for authorities, in the style of
+L<C4::AuthoritiesMarc::SearchAuthorities>.
Arguments:
'match-heading' => 'Match-heading',
'see-from' => 'Match-heading-see-from',
thesaurus => 'Subject-heading-thesaurus',
- '' => '',
+ any => '',
);
# Make sure everything exists
=head2 search
- my $results = $searcher->search($query, $page, $count);
+ my $results = $searcher->search($query, $page, $count, %options);
Run a search using the query. It'll return C<$count> results, starting at page
C<$page> (C<$page> counts from 1, anything less that, or C<undef> becomes 1.)
+C<$count> is also the number of entries on a page.
C<%options> is a hash containing extra options:
=back
+Returns
+
=cut
sub search {
my $params = $self->get_elasticsearch_params();
my %paging;
+ # 20 is the default number of results per page
$paging{limit} = $count || 20;
- # ES doesn't want pages, it wants a record to start from.
+ # ES/Catmandu doesn't want pages, it wants a record to start from.
if (exists $options{offset}) {
$paging{start} = $options{offset};
} else {
$self->store(
Catmandu::Store::ElasticSearch->new(
%$params,
- trace_calls => 0,
+ trace_calls => 1,
)
);
my $results = $self->store->bag->search( %$query, %paging );
return (undef, \%result, $self->_convert_facets($results->{facets}));
}
+=head2 search_marc
+
+ my ( $results, $total ) =
+ $searcher->search_marc( $query, $page, $count, %options );
+
+This has a similar calling convention to L<search>, however it assumes that all
+the results are going to contain MARC, and just provides an arrayref of them,
+along with a count of the total number of results.
+
+=cut
+
+sub search_marc {
+ # TODO this probably should be temporary, until something more
+ # comprehensive is implemented using Koha::RecordProcessor and such.
+ my $self = shift;
+
+ my $res = $self->search(@_);
+ my @records;
+ $res->each(sub {
+ my $marc_json = @_[0]->{record};
+ my $marc = $self->json2marc($marc_json);
+ push @records, $marc;
+ });
+ return (\@records, $res->total);
+}
+
=head2 json2marc
my $marc = $self->json2marc($marc_json);
use C4::Search::History;
use Koha::Authority::Types;
+use Koha::SearchEngine::Search;
+use Koha::SearchEngine::QueryBuilder;
my $query = new CGI;
my $op = $query->param('op') || '';
$resultsperpage = $query->param('resultsperpage');
$resultsperpage = 20 if ( !defined $resultsperpage );
my @tags;
- my ( $results, $total, @fields ) =
- SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator,
- \@value, $startfrom * $resultsperpage,
- $resultsperpage, $authtypecode, $orderby );
+ my $builder = Koha::SearchEngine::QueryBuilder->new();
+ my $searcher = Koha::SearchEngine::Search->new({index => 'authorities'});
+ my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or,
+ \@excluding, \@operator, \@value, $authtypecode, $orderby );
+# use Data::Dumper;
+# die Dumper(\@marclist, \@and_or,
+# \@excluding, \@operator, \@value, $authtypecode, $orderby, $query);
+ my ( $results, $total ) =
+ $searcher->search_marc( $search_query, $startfrom, $resultsperpage );
+
( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "opac-authoritiessearchresultlist.tt",
$to = ( ( $startfrom + 1 ) * $resultsperpage );
}
unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
- my @usedauths = grep { $_->{used} > 0 } @$results;
- $results = \@usedauths;
+# TODO implement usage counts
+# my @usedauths = grep { $_->{used} > 0 } @$results;
+# $results = \@usedauths;
}
# Opac search history
}
$template->param( result => $results ) if $results;
- $template->param( FIELDS => \@fields );
$template->param( orderby => $orderby );
$template->param(
startfrom => $startfrom,