From: Bill Erickson Date: Wed, 29 Oct 2014 21:07:41 +0000 (-0400) Subject: KCLS custom multiclass query scrubbing (squashed legacy commits) X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b8f90c918481256b6effd3c76a9404dfdc200cef;p=working%2FEvergreen.git KCLS custom multiclass query scrubbing (squashed legacy commits) kmain-363_fixed_contains_phrase_all_punctuation Cross-port: 1d8ee0c Puncuation_search_edge_cases Cross-port: 8ed3232 KMAIN 115 - Matches exactly exactly searches not working with parenthases Cross-port: 45dd9f2 kmain-422_sorting_returning_null Cross-port: 2d6f4eb Punctuation-Search_Fixed-keyword-contains-phrase Cross-port: da1f967 Punctuation keyword exact match Cross-port: bcbbe3b --- diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index 159ecd78b9..b1dbdbad0b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -836,14 +836,69 @@ sub multiclass_query { $query =~ s/\+/ /go; $query =~ s/^\s+//go; $query =~ s/\s+/ /go; - $arghash->{query} = $query + $query = kcls_scrub_multiclass_query($query); + $arghash->{query} = $query; } $logger->debug("initial search query => $query") if $query; (my $method = $self->api_name) =~ s/\.query/.staged/o; return $self->method_lookup($method)->dispatch($arghash, $docache); +} + +# KCLS custom query cleanup +sub kcls_scrub_multiclass_query { + my $query = shift; + + # If it is all punctuation search, clobber any 'contains phrase' madness + # [a-z]+: This matches 'title:', 'subject:', etc. and is returned in $1 + # ["!?\.@#\$%\^&\*]+ One or more punctuation without any numbers or letters + # is returned in $2 + # $1$2 Replaces the whole string without the " + $query =~ s/([a-z]+:)"(["!?\.@#\$%\^&\*]+)"/$1$2/g; + + # Clobber 'contains phrase' for keyword too + # ["!?\.@#\$%\^&\*]+ One or more punctuation without any numbers or letters + # is returned in $1 + # $1 Replaces the whole string without the " + $query =~ s/"(["!?\.@#\$%\^&\*]+)"/$1/g; + + # If it is all punctuation search, clobber any 'exact match' madness + # [a-z]+: This matches 'title:', 'subject:', etc. and is returned in $1 + # ["!?\.@#\$%\^&\*]+ One or more punctuation without any numbers or letters + # is returned in $2 + # $1$2 Replaces the whole string without ^ and $ + $query =~ s/([a-z]+:)\^(["!?\.@#\$%\^&\*]+)\$/$1$2/g; + + # Clobber 'exact match' for keyword too + # ["!?\.@#\$%\^&\*]+ One or more punctuation without any numbers or letters + # is returned in $1 + # $1 Replaces the whole string without the ^ and $ + $query =~ s/\^(["!?\.@#\$%\^&\*]+)\$/$1/g; + + # What the user actually typed in with no modifiers + my $actual_query; + + # first seperate the search query from the modifiers + my @modifiers = + ("mattype","item_lang","audience_group","after","sort","site","depth"); + + for my $i (0 .. $#modifiers) { + + if ($query =~ m/(.*) $modifiers[$i]\(.*/) { + $actual_query = $1; + + # Then pull off any extraneous parens + if ($actual_query =~ m/.*[\(\)].*/){ + $actual_query =~ s/[\(\)]//g; + $query =~ s/(.*)( $modifiers[$i]\()/$actual_query$2/g; + } + last; # Kill the loop + } + } + + return $query; } __PACKAGE__->register_method(