Bug 24286 and bug 24264 added some escaping for the forward slash in this authtype, however, when we unescape escaped characters for regex, it appears we break the escaping in FindDuplicateAuthority To test: 0 - Have Koha using Elasticsearch 1 - Set QueryRegexEscapeOptions to 'unescape escaped' 2 - Attempt to add a new 'GENRE/FORM' authority record 3 - On save you get a 500 error Unable to understand your search query, please rephrase and try again. at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Search.pm line 102 [2022/06/23 10:07:02] [WARN] [Request] ** [http://es:9200]-[400] [query_shard_exception] Failed to parse query [(authtype:GENRE/FORM* AND heading:"ddddd")], with: {"index":"koha_kohadev_authorities","index_uuid":"I00T6jgPTKynx5kKc8heNQ"}, called from sub Search::Elasticsearch::Role::Client::Direct::__ANON__ at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Search.pm line 95. With vars: {'request' => {'body' => {'query' => {'query_string' => {'query' => '(authtype:GENRE/FORM* AND heading:"ddddd")','analyze_wildcard' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),'default_operator' => 'AND','fuzziness' => 'auto','type' => 'cross_fields','lenient' => $VAR1->{'request'}{'body'}{'query'}{'query_string'}{'analyze_wildcard'},'fields' => ['lc-card-number','local-number','record-source','personal-name','meeting-name','personal-name-see-also-from','see-from','authtype','meeting-name-see-also-from','match-heading-see-from','heading-use-main-or-added-entry','subject-heading-thesaurus','match','heading-use-series-added-entry','kind-of-record','see-also-from','heading','corporate-name-see-also-from','descriptive-cataloging-rules','meeting-name-see-from','corporate-name-see-from','heading-use-subject-added-entry','personal-name-see-from','personal-name-heading','meeting-name-heading','heading-main']}},'size' => 1,'aggregations' => {'su-geo' => {'terms' => {'size' => '20','field' => 'su-geo__facet'}},'location' => {'terms' => {'size' => '20','field' => 'location__facet'}},'author' => {'terms' => {'field' => 'author__facet','size' => '20'}},'ln' => {'terms' => {'field' => 'ln__facet','size' => '20'}},'holdingbranch' => {'terms' => {'size' => '20','field' => 'holdingbranch__facet'}},'subject' => {'terms' => {'field' => 'subject__facet','size' => '20'}},'itype' => {'terms' => {'field' => 'itype__facet','size' => '20'}},'title-series' => {'terms' => {'field' => 'title-series__facet','size' => '20'}},'ccode' => {'terms' => {'field' => 'ccode__facet','size' => '20'}}},'from' => 0},'mime_type' => 'application/json','serialize' => 'std','method' => 'GET','ignore' => [],'path' => '/koha_kohadev_authorities/_search','qs' => {'track_total_hits' => 'true'}},'status_code' => 400,'body' => {'error' => {'reason' => 'all shards failed','phase' => 'query','type' => 'search_phase_execution_exception','grouped' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ),'failed_shards' => [{'node' => '8aathbKCRVmwFPakemaNEA','index' => 'koha_kohadev_authorities','reason' => {'reason' => 'Failed to parse query [(authtype:GENRE/FORM* AND heading:"ddddd")]','index' => 'koha_kohadev_authorities','type' => 'query_shard_exception','caused_by' => {'type' => 'parse_exception','caused_by' => {'type' => 'token_mgr_error','reason' => 'Lexical error at line 1, column 43. Encountered: <EOF> after : "/FORM* AND heading:\\"ddddd\\")"'},'reason' => 'Cannot parse \'(authtype:GENRE/FORM* AND heading:"ddddd")\': Lexical error at line 1, column 43. Encountered: <EOF> after : "/FORM* AND heading:\\"ddddd\\")"'},'index_uuid' => 'I00T6jgPTKynx5kKc8heNQ'},'shard' => 0}],'root_cause' => [{'index' => 'koha_kohadev_authorities','reason' => 'Failed to parse query [(authtype:GENRE/FORM* AND heading:"ddddd")]','index_uuid' => 'I00T6jgPTKynx5kKc8heNQ','type' => 'query_shard_exception'}]},'status' => 400}}
Created attachment 137631 [details] [review] Bug 31023: Unit tests
Created attachment 137632 [details] [review] Bug 31023: Quote authtypecode in FindDuplicateAuthorities To test: 0 - Have Koha using Elasticsearch 1 - Set QueryRegexEscapeOptions to 'unescape escaped' 2 - Attempt to add a new 'GENRE/FORM' authority record 3 - On save you get a 500 error Unable to understand your search query, please rephrase and try again. at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Search.pm line 102 4 - Apply patch, restart all 5 - Attempt to add a new 'GENRE/FORM' authority record 6 - Success!
Created attachment 137662 [details] [review] Bug 31023: Unit tests Signed-off-by: David Nind <david@davidnind.com>
Created attachment 137663 [details] [review] Bug 31023: Quote authtypecode in FindDuplicateAuthorities To test: 0 - Have Koha using Elasticsearch 1 - Set QueryRegexEscapeOptions to 'unescape escaped' 2 - Attempt to add a new 'GENRE/FORM' authority record 3 - On save you get a 500 error Unable to understand your search query, please rephrase and try again. at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Search.pm line 102 4 - Apply patch, restart all 5 - Attempt to add a new 'GENRE/FORM' authority record 6 - Success! Signed-off-by: David Nind <david@davidnind.com>
Nick, please don't forget to assign yourself!
Created attachment 139852 [details] [review] Bug 31023: Unit tests Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Created attachment 139853 [details] [review] Bug 31023: Quote authtypecode in FindDuplicateAuthorities To test: 0 - Have Koha using Elasticsearch 1 - Set QueryRegexEscapeOptions to 'unescape escaped' 2 - Attempt to add a new 'GENRE/FORM' authority record 3 - On save you get a 500 error Unable to understand your search query, please rephrase and try again. at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch/Search.pm line 102 4 - Apply patch, restart all 5 - Attempt to add a new 'GENRE/FORM' authority record 6 - Success! Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Hi, Nick. Do you think you could use Koha::SearchEngine::Zebra::QueryBuilder::clean_search_term on the authtypecode?
(In reply to Tomás Cohen Arazi from comment #8) > Hi, Nick. Do you think you could use > Koha::SearchEngine::Zebra::QueryBuilder::clean_search_term on the > authtypecode? I think that might be overkill on this one - everythign already works in Zebra - in ES, it only doesn't work under a special case where we are unescaping values as specified by the pref. Ideally, I think we would just remove the slash from the type, GENRE_FORM, or something.
Pushed to master for 22.11. Nice work everyone, thanks!
Backported to 22.05.x for upcoming 22.05.07 release
applied to 21.11.x for 21.11.14
Not backported to oldoldstable (21.05.x). Feel free to ask if it's needed. Nothing to document it seems, marking resolved.