Skip Menu |

This queue is for tickets about the Search-Tools CPAN distribution.

Report information
The Basics
Id: 43379
Status: resolved
Priority: 0/
Queue: Search-Tools

People
Owner: Nobody in particular
Requestors: ANIRVAN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.22
Fixed in: (no value)



Subject: Search::Tools::HiLiter doesn't match terms inside hyphenated phrases
I'd like to have Search::Tools::HiLiter highlight instances of a word that's inside a hyphenated phrase. As it stands right now, it fails to catch words in hyphenated phrases. I'm willing to to enable this matching via a special flag, if needed. Here's an example: use Search::Tools::HiLiter; use Test::More tests => 2; my $hiliter = Search::Tools::HiLiter->new( query => [qw( Kennedy )] ); like( $hiliter->light(q{Martha Kennedy Smith}), qr/<span/, 'hiliter works fine without hyphens' ); like( $hiliter->light(q{Martha Kennedy-Smith}), qr/<span/, 'hiliter ought to work with hyphens' ); Search::Tools works *really* well otherwise, and it's very intuitively designed and documented. Thanks so much for your work.
This feature is already present. You just have to define what a "word" is. There are 2 ways, either with a package var or by explicitly defining a RegExp object with word_characters defined. Your test as an example: use Search::Tools::HiLiter; use Test::More tests => 4; { # package var to control word definition # notice no hyphen, which is in the default def -- # see the RegExp docs local $Search::Tools::RegExp::WordChar = $Search::Tools::RegExp::UTF8Char . quotemeta("'."); my $hiliter = Search::Tools::HiLiter->new( query => [qw( Kennedy )] ); like( $hiliter->light(q{Martha Kennedy Smith}), qr/<span/, 'hiliter works fine without hyphens' ); like( $hiliter->light(q{Martha Kennedy-Smith}), qr/<span/, 'hiliter ought to work with hyphens' ); } diag($Search::Tools::RegExp::WordChar); { # the OO way my $regexp = Search::Tools::RegExp->new( word_characters => '\w' . quotemeta("'.") ); my $hiliter = Search::Tools::HiLiter->new( query => $regexp->build( [qw( Kennedy )] ) ); like( $hiliter->light(q{Martha Kennedy Smith}), qr/<span/, 'hiliter works fine without hyphens' ); like( $hiliter->light(q{Martha Kennedy-Smith}), qr/<span/, 'hiliter ought to work with hyphens' ); }