use Koha::MetadataRecord::Authority;
use Koha::Authorities;
use Koha::Authority::Types;
+use Koha::Authority;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
use vars qw(@ISA @EXPORT);
### ZOOM search here
my $query;
$query= "an:".$authid;
- my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
+ # Should really be replaced with a real count call, this is a
+ # bad way.
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
+ my ($err,$res,$result) = $searcher->simple_search_compat($query,0,1);
if ($err) {
warn "Error: $err from search $query";
$result = 0;
$_->[1]=~s/$filtervalues/ /g; $query.= " $op he:\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
}
}
- my ($error, $results, $total_hits) = C4::Search::SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::AUTHORITIES_INDEX});
+ my ($error, $results, $total_hits) = $searcher->simple_search_compat( $query, 0, 1 );
# there is at least 1 result => return the 1st one
if (!defined $error && @{$results} ) {
my $marcrecord = C4::Search::new_record_from_zebra(
use Koha::Database;
use Koha::Database;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
use vars qw(@ISA @EXPORT);
sub GetAnalyticsCount {
my ($itemnumber) = @_;
- require C4::Search;
### ZOOM search here
my $query;
$query= "hi=".$itemnumber;
- my ($err,$res,$result) = C4::Search::SimpleSearch($query,0,10);
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
+ my ($err,$res,$result) = $searcher->simple_search_compat($query,0,10);
return ($result);
}
use C4::Context;
use MARC::Record;
-
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
=head1 NAME
#NOTE: double-quote the values so you don't get a "Embedded truncation not supported" error when a term has a ? in it.
}
- require C4::Search;
-
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
( $error, $searchresults, $total_hits ) =
- C4::Search::SimpleSearch( $query, 0, $max_matches );
+ $searcher->simple_search_compat( $query, 0, $max_matches );
}
elsif ( $self->{'record_type'} eq 'authority' ) {
my $authresults;
use LWP::UserAgent;
use HTTP::Request::Common;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
use strict;
#use warnings; FIXME - Bug 2505
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
my $xisbn = shift;
my $dbh = C4::Context->dbh;
- my ( $errors, $results, $total_hits ) = C4::Search::SimpleSearch( "nb=$xisbn", 0, 1 );
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
+ my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( "nb=$xisbn", 0, 1 );
return unless ( !$errors && scalar @$results );
my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[0] );
=cut
sub update_index_background {
+ my $self = shift;
$self->update_index(@_);
}
--- /dev/null
+package Koha::SearchEngine;
+# This handles generic search-engine related functions
+
+# Copyright 2015 Catalyst IT
+#
+# This file is part of Koha.
+#
+# 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, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+use Modern::Perl;
+use Readonly;
+
+=head1 NAME
+
+Koha::SearchEngine - non-engine-specific data and functions
+
+=head1 VARIABLES / CONSTANTS
+
+=head2 BIBLIOS_INDEX
+
+Use this constant when creating a new L<Koha::SearchEngine::Search> instance
+to indicate that you want to be working with the biblio index.
+
+=head2 AUTHORITIES_INDEX
+
+Use this constant when creating a new L<Koha::SearchEngine::Search> instance to
+indicate that you want to be working with the authorities index.
+
+=cut
+
+# Search engine implementations should compare against these to determine
+# what bit of storage is being requested. They will be sensible strings so
+# may be used for, e.g., directory names.
+Readonly our $BIBLIOS_INDEX => 'biblios';
+Readonly our $AUTHORITIES_INDEX => 'authorities';
use base qw(Koha::ElasticSearch);
use Koha::ItemTypes;
+use Koha::SearchEngine::QueryBuilder;
use Catmandu::Store::ElasticSearch;
=item C<$max_results>
-The max number of results to return. The default is 1,000 (because unlimited
+The max number of results to return. The default is 100 (because unlimited
is a pretty terrible thing to do.)
=back
$max_results //= 100;
unless (ref $query) {
- # We'll push it through the query builder
+ # We'll push it through the query builder to sanitise everything.
my $qb = Koha::SearchEngine::QueryBuilder->new();
- $query = $qb->build_query($query);
+ (undef,$query) = $qb->build_query_compat(undef, [$query]);
}
my $results = $self->search($query, undef, $max_results, %options);
my @records;
use C4::Budgets qw/ GetBudgetHierarchy /;
use Koha::Acquisition::Bookseller;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+use Koha::SearchEngine::QueryBuilder;
my $input = new CGI;
my $QParser;
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
my $builtquery;
+my $builder = Koha::SearchEngine::QueryBuilder->new();
+my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
if ($QParser) {
$builtquery = $query;
} else {
- my ( $builterror,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
- ( $builterror,$builtquery,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(undef,\@operands);
+ ( undef,$builtquery,undef,undef,undef,undef,undef,undef,undef,undef) = $builder->build_query_compat(undef,\@operands);
}
-my ( $error, $marcresults, $total_hits ) = SimpleSearch( $builtquery, $results_per_page * ( $page - 1 ), $results_per_page );
+my ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($builtquery, $results_per_page * ($page - 1), $results_per_page);
if (defined $error) {
$template->param(
use C4::AuthoritiesMarc;
use utf8;
use open qw[ :std :encoding(utf8) ];
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
my $dbh=C4::Context->dbh;
my $datatypes_query = $dbh->prepare(<<ENDSQL);
my $query;
$query= "an=".$authority->{'authid'};
# search for biblios mapped
- my ($err,$res,$used) = C4::Search::SimpleSearch($query,0,10);
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
+ my ($err,undef,$used) = $searcher->simple_search_compat($query,0,1);
if (defined $err) {
$used = 0;
}
use Koha::ItemTypes;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
my $builder = sub {
my ( $params ) = @_;
my $function_name = $params->{id};
} else {
$op = 'and';
}
+ my $searcher = Koha::SearchEngine::Search->new(
+ { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
$search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype;
- my ( $errors, $results, $total_hits ) = SimpleSearch( $search, $startfrom * $resultsperpage, $resultsperpage );
+ my ( $errors, $results, $total_hits ) =
+ $searcher->simple_search_compat( $search,
+ $startfrom * $resultsperpage,
+ $resultsperpage );
if ( defined $errors ) {
$results = [];
}
use Koha::ItemTypes;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
+sub plugin_parameters {
+ my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
+ return "";
+}
+
sub plugin_javascript {
my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
my $function_name = $field_number;
$op = 'and';
}
$search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype;
- my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage );
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
+ my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($search, $startfrom * $resultsperpage, $resultsperpage );
if (defined $errors ) {
$results = [];
}
use Koha::Database;
use Koha::Patron::Messages;
use Koha::Patron::Images;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
use Date::Calc qw(
Today
{
$template_params->{FALLBACK} = 1;
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
my $query = "kw=" . $barcode;
- my ( $searcherror, $results, $total_hits ) = SimpleSearch($query);
+ my ( $searcherror, $results, $total_hits ) = $searcher->simple_search_compat($query, 0, 10);
# if multiple hits, offer options to librarian
if ( $total_hits > 0 ) {
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','rtype',FALSE,'','leader_/6',NULL,'leader_/6');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','bib-level',FALSE,'','leader_/7',NULL,'leader_/7');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','control-number',FALSE,'','001',NULL,'001');
-INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string',NULL,'001',NULL);
+INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','Local-number',FALSE,'string',NULL,'001',NULL);
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','date-time-last-modified',FALSE,'','005','099d',NULL);
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','microform-generation',FALSE,'','007_/11',NULL,'007_/11');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','material-type',FALSE,'','007','','007');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','subject',TRUE,'string','653a','610','653');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-classification',FALSE,'','952o','995k','952o');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-classification',FALSE,'',NULL,'686',NULL);
-INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string','999c','001','999c');
-INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string',NULL,'0909',NULL);
+INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','Local-number',FALSE,'string','999c','001','999c');
+INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','Local-number',FALSE,'string',NULL,'0909',NULL);
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','itype',TRUE,'string','942c','200b','942c');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','itype',TRUE,'string','952y','995r','952y');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','acqdate',FALSE,'date','952d','9955','952d');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','an',FALSE,'number',NULL,'6219',NULL);
-- Authorities: incomplete
-INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','local-number',FALSE,'string','001',NULL,'001');
+INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Local-number',FALSE,'string','001',NULL,'001');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','authtype',FALSE,'','942a',NULL,'942a');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Kind-of-record',FALSE,'','008_/9',NULL,'008_/9');
INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Descriptive-cataloging-rules',FALSE,'','008_/10',NULL,'008_/10');
use C4::Output qw(output_html_with_http_headers);
use C4::Context;
use C4::Search qw(SimpleSearch);
+use C4::Dates;
use C4::Biblio qw(TransformMarcToKoha);
use C4::Items qw(GetItemInfosOf get_itemnumbers_of);
use C4::Koha qw(GetItemTypes);
use C4::Debug;
use Koha::DateUtils;
+use Koha::SearchEngine::Search;
+
BEGIN {
$debug = $debug || $cgi_debug;
if ($debug) {
}
my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
- ( $error, $marcresults, $total_hits ) =
- SimpleSearch( $ccl_query, $offset, $resultsperpage );
+ my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'});
+ ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($ccl_query, $offset, $resultsperpage);
if (!defined $error && @{$marcresults} ) {
$show_results = @{$marcresults};
}
else {
- $debug and warn "ERROR label-item-search: no results from SimpleSearch";
+ $debug and warn "ERROR label-item-search: no results from simple_search_compat";
# leave $show_results undef
}
use IO::File;
use Pod::Usage;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
use open qw( :std :encoding(UTF-8) );
binmode( STDOUT, ":encoding(UTF-8)" );
my ( $input_marc_file, $number, $offset) = ('',0,0);
$loghandle= IO::File->new($logfile, $writemode) ;
print $loghandle "id;operation;status\n";
}
+
+my $searcher = Koha::SearchEngine::Search->new(
+ {
+ index => (
+ $authorities
+ ? $Koha::SearchEngine::AUTHORITIES_INDEX
+ : $Koha::SearchEngine::BIBLIOS_INDEX
+ )
+ }
+);
+
RECORD: while ( ) {
my $record;
# get records
my $query = build_query( $match, $record );
my $server = ( $authorities ? 'authorityserver' : 'biblioserver' );
$debug && warn $query;
- my ( $error, $results, $totalhits ) = C4::Search::SimpleSearch( $query, 0, 3, [$server] );
+ my ( $error, $results, $totalhits ) = $searcher->simple_search_compat( $query, 0, 3, [$server] );
# changed to warn so able to continue with one broken record
if ( defined $error ) {
warn "unable to search the database for duplicates : $error";
# Koha modules used
use MARC::Record;
use C4::Context;
-use C4::Search;
use Getopt::Long;
+use Koha::SearchEngine::Search;
+
my ( $help, $confirm, $zebraqueue, $silent,$stealth );
GetOptions(
my $sth = $dbh->prepare("SELECT biblionumber FROM biblio");
my $sth_insert = $dbh->prepare("INSERT INTO zebraqueue (biblio_auth_number,operation,server,done) VALUES (?,'specialUpdate','biblioserver',0)");
+my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'});
+
# We get all biblios
$sth->execute;
my ($nbhits);
-
# We check for each biblio
while ( my ($biblionumber) = $sth->fetchrow ) {
- (undef,undef,$nbhits) = SimpleSearch("Local-number=$biblionumber");
+ (undef,undef,$nbhits) = $searcher->simple_search_compat("Local-number=$biblionumber");
print "biblionumber $biblionumber not indexed\n" unless $nbhits || $stealth;
# If -z option we put the biblio in zebraqueue
if ($zebraqueue && !$nbhits){
\t./batchCheckNonIndexedBiblios.pl -s (s like silent => don't throws a warn every 1000 biblios to show progress)
\t./batchCheckNonIndexedBiblios.pl -st (s like stealth => don't throws a warn every 1000 biblios to show progress and no warn for the non indexed biblionumbers, just the total)
_USAGE_
-}
\ No newline at end of file
+}
use C4::AuthoritiesMarc;
use Getopt::Long;
+use Koha::SearchEngine::Search;
+
my @authtypes;
my $want_help = 0;
my $test = 0;
my $counter=0;
my $totdeleted=0;
my $totundeleted=0;
+my $searcher = Koha::SearchEngine::Search->new({index => 'biblios'});
while (my $data=$rqselect->fetchrow_hashref){
my $query;
$query= "an=".$data->{'authid'};
# search for biblios mapped
- my ($err,$res,$used) = C4::Search::SimpleSearch($query,0,10);
+ my ($err,$res,$used) = $searcher->simple_search_compat($query,0,10);
if (defined $err) {
warn "error: $err on search $query\n";
next;
use C4::Biblio;
use C4::Debug;
+use Koha::SearchEngine;
+use Koha::SearchEngine::Search;
+
my $input = new CGI;
my $op = $input->param('op') || q{};
my $dbh = C4::Context->dbh;
$resultsperpage = $input->param('resultsperpage');
$resultsperpage = 20 if ( !defined $resultsperpage );
+ my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
my ( $error, $marcrecords, $total_hits ) =
- SimpleSearch( $query, $startfrom * $resultsperpage, $resultsperpage );
+ $searcher->simple_search_compat( $query, $startfrom * $resultsperpage, $resultsperpage );
my $total = 0;
if ( defined $marcrecords ) {
$total = scalar @{$marcrecords};