Hadn't got much to do, so I thought I'd give it a stab:
use strict; use warnings; use Math::Combinatorics; # Probably best to get stopwords from a file, but for testing: my @stopwords = qw/ the of in on with by and /; my %stop_hash = map { $_ => 1 } @stopwords; my $term = 'Programming Perl, by Wall, Christiansen and Orwant'; my @term = grep { not $stop_hash{lc $_} } split ' ', $term; # Default highlighting combination: n-1 from n (3 from 4, 5 from 6..) my $n_from = shift || @term - 1; my @combos = combine( $n_from, @term ); my $result = highlight( \@combos, $term ); print join "\n", @$result; sub highlight { my $to_highlight = shift; my $term = shift; my @highlighted; foreach my $combo ( @$to_highlight ) { my $str = $term; # Highlight with Caps for console output # $str =~ s/$_/<em>$_</em>/ for @$combo; $str =~ s/$_/\U$_/ for @$combo; push @highlighted, $str; } return \@highlighted; }
Output
PROGRAMMING PERL, by WALL, CHRISTIANSEN and Orwant PROGRAMMING PERL, by WALL, Christiansen and ORWANT PROGRAMMING PERL, by Wall, CHRISTIANSEN and ORWANT PROGRAMMING Perl, by WALL, CHRISTIANSEN and ORWANT Programming PERL, by WALL, CHRISTIANSEN and ORWANT
In reply to Re: Search: "Get more results with fewer keywords"
by Not_a_Number
in thread Search: "Get more results with fewer keywords"
by rmoriz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |