From 1887b8dc8c9fc2a3246a3369bf9237d36c3a5db1 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Tue, 9 May 2023 16:29:23 -0700 Subject: [PATCH] LP1968754: address a few more bugs in instructor search Signed-off-by: Jane Sandberg --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Course.pm | 2 ++ Open-ILS/src/perlmods/t/26-course-opac-search.t | 36 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Course.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Course.pm index 866eb7e2c3..8b7838c68c 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Course.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Course.pm @@ -310,6 +310,8 @@ sub _create_where_clause { my $search_query; if ($type eq 'instructor') { $query =~ s/\*$/:*/; # postgres prefix matching syntax ends with :* (e.g. string:*, not string*) + $query =~ s/^\s+|\s+$//g; # preceding and trailing spaces have the potential to make to_tsquery mad + $query =~ s/\s/ \& /g; # postgres to_tsquery wants & characters between words my $in = ($contains eq 'nocontains') ? "not in" : "in"; $search_query = {'id' => {$in => { 'from' => {'acmcu' => 'acmr'}, diff --git a/Open-ILS/src/perlmods/t/26-course-opac-search.t b/Open-ILS/src/perlmods/t/26-course-opac-search.t index 9d2da1518d..22b52145be 100644 --- a/Open-ILS/src/perlmods/t/26-course-opac-search.t +++ b/Open-ILS/src/perlmods/t/26-course-opac-search.t @@ -1,6 +1,6 @@ #!perl use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 11; use OpenILS::WWW::EGCatLoader; use_ok('OpenILS::WWW::EGCatLoader'); @@ -54,6 +54,40 @@ my $instructor_query_expected = {"-and" => [ is_query_parsed_correctly( \@instructor_query, $instructor_query_expected, 'Create a valid instructor search json query'); +my @instructor_query_with_spaces = {'qtype' => 'instructor','contains' => 'contains','bool' => 'and','value' => 'professor gwendolyn davenport'}; +my $instructor_query_with_spaces_expected = {"-and" => [ + {"owning_lib"=> $orgs}, + {"-not"=>{"+acmc"=>"is_archived"}}, + {"id"=>{"in"=>{ + "where"=>[ + {"+acmr"=>"is_public"}, + {"usr"=>{"in"=> + {"select"=>{"au"=>["id"]}, + "where"=>{"name_kw_tsvector"=> + {"@@"=>{"value"=>["to_tsquery","professor & gwendolyn & davenport"]}}}, + "from"=>"au"}}}], + "select"=>{"acmcu"=>["course"]}, + "from"=>{"acmcu" => "acmr"}}}}]}; +is_query_parsed_correctly( \@instructor_query_with_spaces, $instructor_query_with_spaces_expected, + 'Add & to the ts_query input in json query'); + +my @instructor_query_leading_space = {'qtype' => 'instructor','contains' => 'contains','bool' => 'and','value' => ' gwendolyn'}; +my $instructor_query_leading_space_expected = {"-and" => [ + {"owning_lib"=> $orgs}, + {"-not"=>{"+acmc"=>"is_archived"}}, + {"id"=>{"in"=>{ + "where"=>[ + {"+acmr"=>"is_public"}, + {"usr"=>{"in"=> + {"select"=>{"au"=>["id"]}, + "where"=>{"name_kw_tsvector"=> + {"@@"=>{"value"=>["to_tsquery","gwendolyn"]}}}, + "from"=>"au"}}}], + "select"=>{"acmcu"=>["course"]}, + "from"=>{"acmcu" => "acmr"}}}}]}; +is_query_parsed_correctly( \@instructor_query_leading_space, $instructor_query_leading_space_expected, + 'Removes preceding space before converting to tsquery in json_query'); + my @instructor_prefix_wildcard_query = {'qtype' => 'instructor','contains' => 'contains','bool' => 'and','value' => 'd*'}; my $instructor_prefix_wildcard_query_expected = {"-and" => [ {"owning_lib"=> $orgs}, -- 2.11.0