Bug 12478 - fix syntax errors so that stuff runs
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:
parent
faa4e1f6ec
commit
05fa9bccb0
|
|
@ -40,6 +40,7 @@ provides something that can be given to elasticsearch to get answers.
|
|||
=cut
|
||||
|
||||
use base qw(Class::Accessor);
|
||||
use Carp;
|
||||
use List::MoreUtils qw/ each_array /;
|
||||
use Modern::Perl;
|
||||
use URI::Escape;
|
||||
|
|
@ -225,7 +226,7 @@ sub build_query_compat {
|
|||
);
|
||||
}
|
||||
|
||||
=head2 build_authorites_query
|
||||
=head2 build_authorities_query
|
||||
|
||||
my $query = $builder->build_authorities_query(\%search);
|
||||
|
||||
|
|
@ -259,6 +260,27 @@ The search description is a hashref that looks something like:
|
|||
sub build_authorities_query {
|
||||
my ($self, $search) = @_;
|
||||
|
||||
# Start by making the query parts
|
||||
my @query_parts;
|
||||
my @filter_parts;
|
||||
foreach my $s ( @{ $search->{searches} } ) {
|
||||
my ($wh, $op, $val) = $s->{'where', 'operator', 'value'};
|
||||
my ($q_type);
|
||||
if ($op eq 'is' || $op eq '=') {
|
||||
# look for something that matches completely
|
||||
# note, '=' is about numerical vals. May need special handling.
|
||||
push @filter_parts, { filter => { term => { $wh => $val }} };
|
||||
} elsif ($op eq 'exact') {
|
||||
# left and right truncation, otherwise an exact phrase
|
||||
push @query_parts, { match_phrase => { $wh => $val }};
|
||||
} else {
|
||||
# regular wordlist stuff
|
||||
# TODO truncation
|
||||
push @query_parts, { match => { $wh => $val }};
|
||||
}
|
||||
}
|
||||
# Merge the query and filter parts appropriately
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -291,8 +313,8 @@ 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.
|
||||
must match), = (number exact match), exact (phrase, but with left and right
|
||||
truncation). If left blank, then word list, right truncted, anywhere is used.
|
||||
|
||||
=item value
|
||||
|
||||
|
|
@ -338,8 +360,7 @@ sub build_authorities_query_compat {
|
|||
|
||||
# Make sure everything exists
|
||||
foreach my $m (@$marclist) {
|
||||
confess "Invalid marclist field provided: $m"
|
||||
unless exists $koha_to_index_name{$m};
|
||||
confess "Invalid marclist field provided: $m" unless exists $koha_to_index_name{$m};
|
||||
}
|
||||
for ( my $i = 0 ; $i < @$value ; $i++ ) {
|
||||
push @searches,
|
||||
|
|
@ -356,10 +377,10 @@ sub build_authorities_query_compat {
|
|||
: ( $orderby =~ /^Auth/ ) ? 'Local-Number'
|
||||
: undef;
|
||||
if ($sort_field) {
|
||||
$sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc';
|
||||
my $sort_order = ( $orderby =~ /Asc$/ ) ? 'asc' : 'desc';
|
||||
%sort = ( $orderby => $sort_order, );
|
||||
}
|
||||
%search = (
|
||||
my %search = (
|
||||
searches => \@searches,
|
||||
authtypecode => $authtypecode,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package Koha::SearchEngine::ElasticSearch::Search;
|
||||
package Koha::SearchEngine::Elasticsearch::Search;
|
||||
|
||||
# Copyright 2014 Catalyst IT
|
||||
#
|
||||
|
|
@ -44,7 +44,7 @@ use Catmandu::Store::ElasticSearch;
|
|||
use Data::Dumper; #TODO remove
|
||||
use Carp qw(cluck);
|
||||
|
||||
Koha::SearchEngine::ElasticSearch::Search->mk_accessors(qw( store ));
|
||||
Koha::SearchEngine::Elasticsearch::Search->mk_accessors(qw( store ));
|
||||
|
||||
=head2 search
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ and just get whatever querybuilder you need.
|
|||
Creates a new C<QueryBuilder> of whatever the relevant type is.
|
||||
|
||||
=cut
|
||||
|
||||
use C4::Context;
|
||||
use Modern::Perl;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,58 @@
|
|||
package Koha::SearchEngine::Search;
|
||||
|
||||
# This file is part of Koha.
|
||||
#
|
||||
# Copyright 2015 Catalyst IT
|
||||
#
|
||||
# Koha is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Koha is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||
|
||||
# This is a shim that gives you the appropriate search object for your
|
||||
# system preference.
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::SearchEngine::Search - instantiate the search object that corresponds to
|
||||
the C<SearchEngine> system preference.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This allows you to be agnostic about what the search engine configuration is
|
||||
and just get whatever search object you need.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use Koha::SearchEngine::Search;
|
||||
my $searcher = Koha::SearchEngine::Search->new();
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
=head2 new
|
||||
|
||||
Creates a new C<Search> of whatever the relevant type is.
|
||||
|
||||
=cut
|
||||
|
||||
use C4::Context;
|
||||
use Modern::Perl;
|
||||
|
||||
sub new {
|
||||
my $engine = C4::Context->preference("SearchEngine");
|
||||
my $file = "Koha/SearchEngine/${engine}/Search.pm";
|
||||
my $class = "Koha::SearchEngine::${engine}::Search";
|
||||
require $file;
|
||||
shift @_;
|
||||
return $class->new(@_);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
@ -32,28 +32,14 @@ use List::MoreUtils q/any/;
|
|||
|
||||
use Data::Dumper; # TODO remove
|
||||
|
||||
use Koha::ElasticSearch::Search;
|
||||
use Koha::SearchEngine::Search;
|
||||
use Koha::SearchEngine::QueryBuilder;
|
||||
use Koha::SearchEngine::Zebra::Search;
|
||||
|
||||
my $searchengine = C4::Context->preference("SearchEngine");
|
||||
my ($builder, $searcher);
|
||||
#$searchengine = 'Zebra'; # XXX
|
||||
$builder = Koha::SearchEngine::QueryBuilder->new();
|
||||
for ( $searchengine ) {
|
||||
when ( /^Solr$/ ) {
|
||||
warn "We use Solr";
|
||||
require 'opac/search.pl';
|
||||
exit;
|
||||
}
|
||||
when ( /^Zebra$/ ) {
|
||||
$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'});
|
||||
}
|
||||
}
|
||||
$builder = Koha::SearchEngine::QueryBuilder->new();
|
||||
$searcher = Koha::SearchEngine::Search->new({index => 'biblios'});
|
||||
|
||||
use C4::Output;
|
||||
use C4::Auth qw(:DEFAULT get_session);
|
||||
|
|
|
|||
Loading…
Reference in New Issue