Bugzilla – Attachment 61806 Details for
Bug 18374
Respect QueryAutoTruncate syspref in Elasticsearch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18374 - Respect QueryAutoTruncate syspref in Elasticsearch
Bug-18374---Respect-QueryAutoTruncate-syspref-in-E.patch (text/plain), 2.06 KB, created by
Nick Clemens (kidclamp)
on 2017-04-03 18:37:07 UTC
(
hide
)
Description:
Bug 18374 - Respect QueryAutoTruncate syspref in Elasticsearch
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2017-04-03 18:37:07 UTC
Size:
2.06 KB
patch
obsolete
>From 6c20d5ab03345663bcee21b95555bf2fdfb618d6 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 3 Apr 2017 14:30:44 -0400 >Subject: [PATCH] Bug 18374 - Respect QueryAutoTruncate syspref in > Elasticsearch > >This patchset adds a subroutine '_truncate_terms' to the ES QueryParser. > >If QueryAutoTruncate is enabled this function will be called for any >search to add wildcard '*' to all terms > >To test: >1 - Enable Elasticsearch and have some records indexed >2 - Search for partial terms >3 - Note they fail unless '*' is appended >4 - Apply patch, leave QueryAutoTruncate disabled >5 - Note partial term searches still fail >6 - Enable QueryAutoTruncate >7 - Note partial term searches succeed >8 - Do some regular and advanced searches to make sure results are as >expected >--- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 24 ++++++++++++++++++++++++ > 1 file changed, 24 insertions(+) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index fbd4370..f12f27a 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -83,6 +83,7 @@ sub build_query { > my $fuzzy_enabled = C4::Context->preference("QueryFuzzy") || 0; > > $query = '*' unless defined $query; >+ $query = $self->_truncate_terms($query) if ( $auto_truncation ); > > my $res; > $res->{query} = { >@@ -779,4 +780,27 @@ sub _sort_field { > return $f; > } > >+=head2 _truncate_terms >+ >+ my $query = $self->_truncate_terms($query); >+ >+Given a string query this function appends '*' wildcard to all terms except >+operands. >+ >+=cut >+ >+sub _truncate_terms { >+ my ($self, $query) = @_; >+ my @stops = qw/and or not/; >+ my @new_terms =''; >+ my @split_query = split /[\(\s\)]/, $query ; >+ foreach my $term ( @split_query ) { >+ next if ($term eq '' || $term eq ' ') ; >+ $term .= "*" unless ( grep { $term =~ /$_/ } @stops ); >+ push @new_terms, $term; >+ } >+ $query="(".( join ' ' ,@new_terms ).")"; >+ return $query; >+} >+ > 1; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18374
:
61806
|
61952
|
61953
|
61954
|
61955
|
61983
|
64903
|
64904
|
67098
|
67099
|
67100
|
67467
|
67468
|
67469
|
67470
|
67727
|
68062
|
68063
|
68064
|
68065
|
68066
|
68067
|
68068