Bug 20273: Use compat routines for autocomplete in auth_finder.pl
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 6 Aug 2018 13:00:54 +0000 (14:00 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 6 Aug 2018 13:00:54 +0000 (14:00 +0100)
Test plan:
  - Context: Koha working with elasticsearch,
  - Apply BZ 19582 (that make auth_finder.pl works again),
  - apply this patch,
  - go to cgi-bin/koha/authorities/auth_finder.pl,
  - type at least 3 chararcters in a search field and
    check that the autocomplete returns results

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 96e768eb43a1555ae2f03b098edddbd051e8ae80)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/SearchEngine/Elasticsearch/Search.pm
authorities/ysearch.pl
koha-tmpl/intranet-tmpl/prog/js/auth-finder-search.js

index a1598d7..6340ebe 100644 (file)
@@ -42,6 +42,7 @@ use Modern::Perl;
 
 use base qw(Koha::SearchEngine::Elasticsearch);
 use C4::Context;
+use C4::AuthoritiesMarc;
 use Koha::ItemTypes;
 use Koha::AuthorisedValues;
 use Koha::SearchEngine::QueryBuilder;
index 4a5ae79..9861f87 100755 (executable)
@@ -33,9 +33,10 @@ use JSON;
 
 use C4::Context;
 use C4::Charset;
-use C4::AuthoritiesMarc;
 use C4::Auth qw/check_cookie_auth/;
 use C4::Output;
+use Koha::SearchEngine::Search;
+use Koha::SearchEngine::QueryBuilder;
 
 my $query = new CGI;
 
@@ -60,7 +61,18 @@ if ( $auth_status ne "ok" ) {
     my $resultsperpage = 50;
     my $startfrom = 0;
 
-    my ( $results, $total ) = SearchAuthorities( \@marclist, \@and_or, \@excluding, \@operator, \@value, $startfrom * $resultsperpage, $resultsperpage, $authtypecode, $orderby );
+    my $builder = Koha::SearchEngine::QueryBuilder->new(
+        { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
+    my $searcher = Koha::SearchEngine::Search->new(
+        { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
+    my $search_query = $builder->build_authorities_query_compat(
+        \@marclist, \@and_or, \@excluding, \@operator,
+        \@value, $authtypecode, $orderby
+    );
+    my $offset = $startfrom * $resultsperpage;
+    my ( $results, $total ) =
+        $searcher->search_auth_compat( $search_query, $offset,
+        $resultsperpage );
 
     my %used_summaries; # hash to avoid duplicates
     my @summaries;
index 2e853e2..f629f5d 100644 (file)
@@ -23,7 +23,7 @@ $(document).ready(function(){
                     and_or: "and",
                     operator: "contains",
                     orderby: "HeadingAsc",
-                    querytype: "marclist"
+                    querytype: "all"
                 },
                 success: function(data) {
                     response( $.map( data, function( item ) {