On Tue, Aug 28, 2012 at 8:25 PM, Peter Karman <[email protected]> wrote:
> in the current class setup, I would need something like this in make_matcher()
> in MyCompiler then?
>
>  sub make_matcher {
>      my $self = shift;
>      my $child_matcher = $self->SUPER::make_matcher(@_);
>      return MyMatcher->new( child => $child_matcher );
>  }
>
> or am I misunderstanding?

I left a lot out. :)

I'd suggest generalizing your class and having it wrap an arbitrary Query.

    {
        package MyQuery;
        use base qw( Lucy::Search::Query );

        my %child;

        sub new {
            my ($class, %args) = @_;
            my $child = delete $args{child};
            confess "not a Query"
                unless (blessed($child)
                and $child->isa("Lucy::Search::Query"));
            my $self = $class->SUPER::new(%args);
            $child{$$self} = $child;
            return $self;
        }

        ...

        sub make_compiler {
            my ($self, %args) = @_;
            my $child_compiler = $child{$$self}->make_compiler(%args);
            my $compiler = MyCompiler->new(child => $child_compiler);
            $compiler->normalize unless $args{subordinate};
            return $compiler;
        }
    }

    {
        package MyCompiler;
        use base qw( Lucy::Search::Compiler );

        my %child;

        sub new {
            my ($class, %args) = @_;
            my $child = delete $args{child};
            my $self = $class->SUPER::new(%args);
            $child{$$self} = $child;
            return $self;
        }

        ...

        sub make_matcher {
            my ($self, %args) = @_;
            my $child_matcher = $child{$$self}->make_matcher(%args);
            return unless $child_matcher;
            my $sort_reader = $args{reader}->obtain("Lucy::Index::SortReader");
            my $sort_cache  = $sort_reader->fetch_sort_cache("magic");
            return MyMatcher->new(
                child      => $child_matcher,
                sort_cache => $sort_cache,
            );
        }
    }

Does that make sense?

> I like the idea of making SortReader and SortCache public, just because I
> imagine it would be nice abuse them like this for other reasons. But I
> understand the once-public-always-public threshold.

It's so challenging to evolve sensible APIs...

Marvin Humphrey

Reply via email to