On Mar 29, 2007, at 3:07 PM, Chris Nandor wrote:
> Patches included for RangeFilter.pm and t/512
This looks great.
First I had to fix a memory glitch in MatchFieldScorer.c that your
patch revealed. You'll need to svn up.
After that, I applied your changes as revision 2232. Thanks!
> (and one housekeeping patch for QueryFilter).
This cracked me up. :)
Index: lib/KinoSearch/Search/QueryFilter.pm
===================================================================
--- lib/KinoSearch/Search/QueryFilter.pm (revision 2230)
+++ lib/KinoSearch/Search/QueryFilter.pm (working copy)
@@ -9,8 +9,6 @@
__PACKAGE__->init_instance_vars(
# constructor params / members
query => undef,
- # members
- cached_bits => undef,
);
}
I was actually going to make some minor changes to your
implementation, but I hadn't wanted to nitpick. ;)
The %instance_vars hash in each class serves two purposes.
First, labeled constructor args are checked against its members, so
that misspelled argument labels cause errors rather than obscure bugs.
Second, it serves as a template of default values from which hash-
based objects get cloned.
Since this has come up though, I've applied the patch below instead,
which is more consistent in relation to the rest of KS. (Except for
the fact that it doesn't use __PACKAGE__->init_instance_vars, but I'm
about to kill that off globally.)
Marvin Humphrey
Rectangular Research
http://www.rectangular.com/ $ svn diff ..
Index: ../perl/lib/KinoSearch/Search/QueryFilter.pm
===================================================================
--- ../perl/lib/KinoSearch/Search/QueryFilter.pm (revision 2230)
+++ ../perl/lib/KinoSearch/Search/QueryFilter.pm (working copy)
@@ -5,15 +5,14 @@
use KinoSearch::Util::ToolSet;
use base qw( KinoSearch::Util::Class );
-BEGIN {
- __PACKAGE__->init_instance_vars(
- # constructor params / members
- query => undef,
- # members
- cached_bits => undef,
- );
-}
+our %instance_vars = (
+ # constructor params / members
+ query => undef,
+ # members
+ cached_bits => {},
+);
+
use KinoSearch::Search::HitCollector;
use KinoSearch::Util::BitVector;
@@ -26,11 +25,11 @@
sub bits {
my ( $self, $reader ) = @_;
- my $cached_bits = $self->{$reader}{cached_bits};
+ my $cached_bits = $self->{cached_bits}{$reader};
# fill the cache
if ( !defined $cached_bits ) {
- $self->{$reader}{cached_bits} = $cached_bits =
KinoSearch::Util::BitVector->new(
+ $self->{cached_bits}{$reader} = $cached_bits =
KinoSearch::Util::BitVector->new(
capacity => $reader->max_doc );
my $collector = KinoSearch::Search::HitCollector-
>new_bit_coll(