Bug 12478 - authority work in progress

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jesse Weaver <jweaver@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Brendan Gallagher <brendan@bywatersolutions.com>
This commit is contained in:
Robin Sheat 2015-01-30 16:06:46 +13:00 committed by Brendan Gallagher
parent 205260bd63
commit faa4e1f6ec
4 changed files with 149 additions and 6 deletions

View File

@ -21,7 +21,6 @@ use base qw(Class::Accessor);
use C4::Context;
use Carp;
use Elasticsearch;
use Koha::Database;
use Modern::Perl;
use Readonly;

View File

@ -122,7 +122,7 @@ to be searched must have been indexed with an appropriate mapping as a
"phrase" subfield.
=cut
# XXX this isn't really a browse query like we want in the end
sub build_browse_query {
my ( $self, $field, $query ) = @_;
@ -225,6 +225,149 @@ sub build_query_compat {
);
}
=head2 build_authorites_query
my $query = $builder->build_authorities_query(\%search);
This takes a nice description of an authority search and turns it into a black-box
query that can then be passed to the appropriate searcher.
The search description is a hashref that looks something like:
{
searches => [
{
where => 'Heading', # search the main entry
operator => 'exact', # require an exact match
value => 'frogs', # the search string
},
{
where => '', # search all entries
operator => '', # default keyword, right truncation
value => 'pond',
},
],
sort => {
field => 'Heading',
order => 'desc',
},
authtypecode => 'TOPIC_TERM',
}
=cut
sub build_authorities_query {
my ($self, $search) = @_;
}
=head2 build_authorities_query_compat
my ($query) =
$builder->build_authorities_query_compat( \@marclist, \@and_or,
\@excluding, \@operator, \@value, $authtypecode, $orderby );
This builds a query for searching for authorities.
Arguments:
=over 4
=item marclist
An arrayref containing where the particular term should be searched for.
Options are: mainmainentry, mainentry, match, match-heading, see-from, and
thesaurus. If left blank, any field is used.
=item and_or
Totally ignored. It is never used in L<C4::AuthoritiesMarc::SearchAuthorities>.
=item excluding
Also ignored.
=item operator
What form of search to do. Options are: is (phrase, no trunction, whole field
must match), = (number exact match), exact (same as 'is'?). If left blank,
then word list, right truncted, anywhere is used.
=item value
The actual user-provided string value to search for.
=authtypecode
The authority type code to search within. If blank, then all will be searched.
=orderby
The order to sort the results by. Options are Relevance, HeadingAsc,
HeadingDsc, AuthidAsc, AuthidDsc.
=back
marclist, operator, and value must be the same length, and the values at
index /i/ all relate to each other.
This returns a query, which is a black box object that can be passed to the
appropriate search object.
=cut
sub build_authorities_query_compat {
my ( $self, $marclist, $and_or, $excluding, $operator, $value,
$authtypecode, $orderby )
= @_;
# This turns the old-style many-options argument form into a more
# extensible hash form that is understood by L<build_authorities_query>.
my @searches;
my %koha_to_index_name = (
mainmainentry => 'Heading-Main',
mainentry => 'Heading',
match => 'Match',
'match-heading' => 'Match-heading',
'see-from' => 'Match-heading-see-from',
thesaurus => 'Subject-heading-thesaurus',
'' => '',
);
# Make sure everything exists
foreach my $m (@$marclist) {
confess "Invalid marclist field provided: $m"
unless exists $koha_to_index_name{$m};
}
for ( my $i = 0 ; $i < @$value ; $i++ ) {
push @searches,
{
where => $marclist->[$i],
operator => $operator->[$i],
value => $value->[$i],
};
}
my %sort;
my $sort_field =
( $orderby =~ /^Heading/ ) ? 'Heading'
: ( $orderby =~ /^Auth/ ) ? 'Local-Number'
: undef;
if ($sort_field) {
$sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc';
%sort = ( $orderby => $sort_order, );
}
%search = (
searches => \@searches,
authtypecode => $authtypecode,
);
$search{sort} = \%sort if %sort;
my $query = $self->build_authorities_query( \%search );
return $query;
}
=head2 _convert_sort_fields
my @sort_params = _convert_sort_fields(@sort_by)

View File

@ -1,4 +1,4 @@
package Koha::ElasticSearch::Search;
package Koha::SearchEngine::ElasticSearch::Search;
# Copyright 2014 Catalyst IT
#
@ -19,11 +19,11 @@ package Koha::ElasticSearch::Search;
=head1 NAME
Koha::ElasticSearch::Search - search functions for Elasticsearch
Koha::SearchEngine::ElasticSearch::Search - search functions for Elasticsearch
=head1 SYNOPSIS
my $searcher = Koha::ElasticSearch::Search->new();
my $searcher = Koha::SearchEngine::ElasticSearch::Search->new();
my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new();
my $query = $builder->build_query('perl');
my $results = $searcher->search($query);
@ -44,7 +44,7 @@ use Catmandu::Store::ElasticSearch;
use Data::Dumper; #TODO remove
use Carp qw(cluck);
Koha::ElasticSearch::Search->mk_accessors(qw( store ));
Koha::SearchEngine::ElasticSearch::Search->mk_accessors(qw( store ));
=head2 search

View File

@ -50,6 +50,7 @@ for ( $searchengine ) {
$searcher=Koha::SearchEngine::Zebra::Search->new();
}
when (/^Elasticsearch$/) {
# TODO refactor Koha::ES::Search into Koha::SE::ES::Search
$searcher=Koha::ElasticSearch::Search->new({index => 'biblios'});
}
}