$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(