[interchange-cvs] interchange - heins modified 2 files
interchange-core@interchange.redhat.com
interchange-core@interchange.redhat.com
Thu Jan 31 22:21:01 2002
User: heins
Date: 2002-02-01 03:20:11 GMT
Modified: lib/Vend Search.pm TextSearch.pm
Log:
* Fix nasty search bug in TextSearch, caused trashing of searches
by overwriting $_.
* Remove redundant code in both Search.pm and TextSearch.pm
* Remove passed argument for escape_scan, was already the default.
Revision Changes Path
2.3 +11 -13 interchange/lib/Vend/Search.pm
rev 2.3, prev_rev 2.2
Index: Search.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/Search.pm,v
retrieving revision 2.2
retrieving revision 2.3
diff -u -r2.2 -r2.3
--- Search.pm 6 Dec 2001 20:44:02 -0000 2.2
+++ Search.pm 1 Feb 2002 03:20:10 -0000 2.3
@@ -1,6 +1,6 @@
# Vend::Search - Base class for search engines
#
-# $Id: Search.pm,v 2.2 2001/12/06 20:44:02 jon Exp $
+# $Id: Search.pm,v 2.3 2002/02/01 03:20:10 mheins Exp $
#
# Copyright (C) 1996-2001 Red Hat, Inc. <interchange@redhat.com>
#
@@ -21,7 +21,7 @@
package Vend::Search;
-$VERSION = substr(q$Revision: 2.2 $, 10);
+$VERSION = substr(q$Revision: 2.3 $, 10);
use strict;
use vars qw($VERSION);
@@ -416,13 +416,12 @@
my ($return_sub);
if($makeref) {
-
# Avoid the hash key lookup, it is a closure
my $delim = $s->{mv_index_delim};
# We will pick out the return fields later if sorting
# This returns
- if(! $final and $s->{mv_sort_field}) {
+ if( $s->{mv_sort_field} ) {
return (
sub {
[ split /$delim/o, shift(@_) ]
@@ -430,18 +429,17 @@
1,
);
}
-
- if(! $s->{mv_return_fields}) {
+ elsif($s->{mv_return_fields}) {
+ my @fields = @{$s->{mv_return_fields}};
$return_sub = sub {
- $_[0] =~ s/$delim.*//s;
- return $_[0];
+ return [ (split /$delim/o, shift(@_))[@fields] ]
};
}
else {
- my @fields = @{$s->{mv_return_fields}};
$return_sub = sub {
- return [ (split /$delim/o, shift(@_))[@fields] ]
- };
+ $_[0] =~ s/$delim.*//s;
+ return [ $_[0] ];
+ };
}
}
else {
@@ -826,8 +824,8 @@
}
$code .= $range_code;
$code .= <<EOF;
- \$_ = join q{$s->{mv_index_delim}}, \@\$line[$fields];
- return(\$_ = \$line) if &\$sub();
+ local(\$_) = join q{$s->{mv_index_delim}}, \@\$line[$fields];
+ return(1) if &\$sub();
return undef;
}
EOF
2.4 +12 -15 interchange/lib/Vend/TextSearch.pm
rev 2.4, prev_rev 2.3
Index: TextSearch.pm
===================================================================
RCS file: /anon_cvs/repository/interchange/lib/Vend/TextSearch.pm,v
retrieving revision 2.3
retrieving revision 2.4
diff -u -r2.3 -r2.4
--- TextSearch.pm 29 Dec 2001 19:49:33 -0000 2.3
+++ TextSearch.pm 1 Feb 2002 03:20:10 -0000 2.4
@@ -1,6 +1,6 @@
# Vend::TextSearch - Search indexes with Perl
#
-# $Id: TextSearch.pm,v 2.3 2001/12/29 19:49:33 mheins Exp $
+# $Id: TextSearch.pm,v 2.4 2002/02/01 03:20:10 mheins Exp $
#
# Adapted for use with Interchange from Search::TextSearch
#
@@ -28,7 +28,7 @@
use vars qw(@ISA);
@ISA = qw(Vend::Search);
-$VERSION = substr(q$Revision: 2.3 $, 10);
+$VERSION = substr(q$Revision: 2.4 $, 10);
use Search::Dict;
use strict;
@@ -268,10 +268,9 @@
if($s->{mv_dict_end} && defined $limit_sub) {
while(<SEARCH>) {
-#::logDebug("$_");
last if $dict_limit->($_);
- next unless &$f();
next unless $limit_sub->($_);
+ chomp;
(push @out, $searchfile and last)
if $s->{mv_return_file_name};
push @out, $return_sub->($_);
@@ -281,34 +280,30 @@
while(<SEARCH>) {
last if $dict_limit->($_);
next unless &$f();
+ chomp;
(push @out, $searchfile and last)
if $s->{mv_return_file_name};
push @out, $return_sub->($_);
}
}
- elsif(! defined $f and defined $limit_sub) {
+ elsif($limit_sub) {
+#::logDebug("limit_sub");
while(<SEARCH>) {
next unless $limit_sub->($_);
+ chomp;
(push @out, $searchfile and last)
if $s->{mv_return_file_name};
push @out, $return_sub->($_);
}
}
- elsif(defined $limit_sub) {
- while(<SEARCH>) {
- next unless &$f();
- next unless $limit_sub->($_);
- (push @out, $searchfile and last)
- if $s->{mv_return_file_name};
- push @out, $return_sub->($_);
- }
- }
- elsif (!defined $f) {
+ elsif (! $f) {
return $s->search_error('No search definition');
}
else {
+#::logDebug("no limit_sub");
while(<SEARCH>) {
next unless &$f();
+ chomp;
(push @out, $searchfile and last)
if $s->{mv_return_file_name};
push @out, $return_sub->($_);
@@ -321,6 +316,7 @@
$s->{matches} = scalar(@out);
#::logDebug("before delayed return: self=" . ::Vend::Util::uneval_it({%$s}));
+#::logDebug("before delayed return: out=" . ::Vend::Util::uneval_it(\@out));
if($delayed_return and $s->{matches} > 0) {
$s->hash_fields($s->{mv_field_names}, qw/mv_sort_field/);
#::logDebug("after hash fields: self=" . ::Vend::Util::uneval_it({%$s}));
@@ -329,6 +325,7 @@
@out = map { $delayed_return->($_) } @out;
}
#::logDebug("after delayed return: self=" . ::Vend::Util::uneval_it({%$s}));
+#::logDebug("after delayed return: out=" . ::Vend::Util::uneval_it(\@out));
if($s->{mv_unique}) {
my %seen;