# STOPWORDS
sub _remove_stopwords {
my ($operand,$index) = @_;
+ my @stopwords_removed;
# phrase and exact-qualified indexes shoudln't have stopwords removed
if ($index!~m/phr|ext/){
# remove stopwords from operand : parse all stopwords & remove them (case insensitive)
# otherwise, a french word like "leçon" woudl be split into "le" "çon", le
# is an empty word, we get "çon" and wouldn't find anything...
foreach (keys %{C4::Context->stopwords}) {
- next if ($_ =~/(and|or|not)/); # don't remove operators
- $operand=~ s/\P{IsAlpha}$_\P{IsAlpha}/ /i;
- $operand=~ s/^$_\P{IsAlpha}/ /i;
- $operand=~ s/\P{IsAlpha}$_$/ /i;
+ next if ($_ =~/(and|or|not)/); # don't remove operators
+ if ($operand =~ /(\P{IsAlpha}$_\P{IsAlpha}|^$_\P{IsAlpha}|\P{IsAlpha}$_$)/) {
+ $operand=~ s/\P{IsAlpha}$_\P{IsAlpha}/ /gi;
+ $operand=~ s/^$_\P{IsAlpha}/ /gi;
+ $operand=~ s/\P{IsAlpha}$_$/ /gi;
+ push @stopwords_removed, $_;
+ }
}
}
- return $operand;
+ return ($operand, \@stopwords_removed);
}
# TRUNCATION
my $simple_query = $operands[0];
my $query_cgi;
my $query_desc;
+ my $query_type;
my $limit;
my $limit_cgi;
my $limit_desc;
+ my $stopwords_removed;
# STEP I: determine if this is a form-based / simple query or if it's nested
# check if this is a known query language query, if it is, return immediately,
my $index_plus_comma="$index," if $index;
# Remove Stopwords
- $operand = _remove_stopwords($operand,$index);
+ ($operand, $stopwords_removed) = _remove_stopwords($operand,$index);
warn "OPERAND w/out STOPWORDS: >$operand<" if $DEBUG;
-
+ warn "REMOVED STOPWORDS: @$stopwords_removed" if $DEBUG;
my $indexes_set;
# Detect Truncation
warn "LIMIT CGI:".$limit_cgi if $DEBUG;
warn "LIMIT DESC:".$limit_desc if $DEBUG;
- return ( undef, $query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc );
+ return ( undef, $query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type );
}
# IMO this subroutine is pretty messy still -- it's responsible for
my $expanded_facet = $params->{'expand'};
# Define some global variables
-my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
+my ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type);
my @results;
## I. BUILD THE QUERY
-( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by);
+( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by);
## parse the query_cgi string and put it into a form suitable for <input>s
my @query_inputs;
if ($query_desc || $limit_desc) {
$template->param(searchdesc => 1);
}
+ $template->param(stopwords_removed => "@$stopwords_removed");
$template->param(results_per_page => $results_per_page);
$template->param(SEARCH_RESULTS => \@newresults);
## Build the page numbers on the bottom of the page