[KinoSearch] Subclassable Highlighter
Marvin Humphrey
marvin at rectangular.com
Wed Jan 30 15:48:51 PST 2008
A thought about Highlighter's constructor...
my $highlighter = KinoSearch::Highlight::Highlighter->new(
searcher => $searcher, # required
query => $query, # required
field => 'content', # required
excerpt_length => 150, # default: 200
formatter => $formatter, # default: a SimpleHTMLFormatter
encoder => $encoder, # default: a SimpleHTMLEncoder
);
In the design we've arrived at, there are a few more constructor args
to Highlighter than I might like. This works OK with labeled args in
Perl, but starts to get a little crazy in C or Java:
Highlighter*
Highlighter_new(const char *class_name, Searcher *searcher, Query
*query,
ByteBuf *field, u32_t excerpt_length, Formatter
*formatter,
Encoder *encoder)
Plus, the Formatter and the Encoder are esoteric, and I think it
makes sense to de-emphasize them.
How about we remove them from the constructor and use defaulting
accessors instead?
sub set_encoder {
my ($self, $encoder) = @_;
confess("Not a KinoSearch::Highlight::Encoder")
unless a_isa_b( $encoder, 'KinoSearch::Highlight::Encoder' );
$encoder{$$self} = $encoder;
}
sub get_encoder {
my $self = shift;
if ( !$encoder{$$self} ) {
$encoder{$$self} =
KinoSearch::Highlight::SimpleHTMLEncoder->new;
}
return $encoder{$$self};
}
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