[KinoSearch] Subclassable Highlighter

Marvin Humphrey marvin at rectangular.com
Sat Jan 26 06:36:00 PST 2008




On Jan 25, 2008, at 1:39 PM, Father Chrysostomos wrote:

>
> On Jan 24, 2008, at 9:45 AM, Father Chrysostomos wrote:
>
>> The [hit] object could have %{} overloading, but that would cause  
>> extra overhead, as the method would have to check ‘caller’ each  
>> time, to make sure it’s not KS:H:Highlighter. But since the number  
>> of hits is likely to be relatively small, maybe that’s not too bad.

> Here’s a patch that implements KS:S:Hits that way:

This works.  :)

In fact, it works better than you think.

I see that you're working off of one of the CPAN releases, since  
you're basing KinoSearch::Search::Hit on KinoSearch::Util::Class,  
which has gone away in svn trunk.  You can check out a copy of trunk  
here:

   svn co http://www.rectangular.com/svn/kinosearch/trunk ks

Please note that trunk isn't stable -- the file format is in flux.   
(In case you're running anything live that would be affected.)

In trunk, everything is now a subclass of KinoSearch::Obj, which uses  
the inside-out model for Perl-space member vars.  Because Obj isn't  
hash-based, there's no need to check caller():

   use overload
       fallback => 1,
       '%{}'    => \&get_hashref;

There happens to be a glitch, but I'm sure it's solvable.  When I add  
overloading to a class based on Obj, it works in 5.10.0 but fails in  
5.8.8.  This is presumably due to a bug in a perlapi function back in  
5.8.8: sv_bless() (or whatever) isn't adding overload magic.  We'll  
have to do that manually.  However, I'm not quite sure what the exact  
XS incantation is, so I'll have to work up a test case and post to  
PerlMonks.

This hashref-overloading is cool enough that I'm going to bring back  
the Doc class and use it for that:

    # (both params are optional)
    my $doc = KinoSearch::Doc->new(
       fields => { title => 'foo' },
       boost  => 3,
    );
    $doc->{content} = "foo foo";

    # (passing a plain hashref will trigger an internal call to Doc- 
 >new)
    $invindexer->add_doc($doc);

In fact, I think Hit should be a subclass of Doc, with the only  
change being that $hit->get_boost throws an error (because Doc's  
index-time boost is not preserved accurately in the index).

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/



_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch




More information about the kinosearch mailing list