use Constants qw(@SEARCH_EXCLUDE @SEARCH_INCLUDE);
use BSE::TB::Articles;
-our $VERSION = "1.006";
+our $VERSION = "1.007";
my %default_scores =
(
my $indexer_class = $cfg->entry('search', 'indexer', 'BSE::Index::BSE');
(my $indexer_file = $indexer_class . ".pm") =~ s!::!/!g;
require $indexer_file;
+ my $case_sensitivity = $cfg->entry('search', 'case_sensitive', 'context');
+ $case_sensitivity =~ /^(none|context|controlled)$/
+ or die "[search].case_sensitive must be none, context or controlled\n";
$self->{indexer} = $indexer_class->new
(
cfg => $cfg,
scores => $self->{scores},
verbose => $self->{verbose},
+ case => $case_sensitivity,
);
}
use Constants qw($MAXPHRASE);
use BSE::CfgInfo qw(cfg_data_dir);
-our $VERSION = "1.003";
+our $VERSION = "1.004";
sub new {
my ($class, %opts) = @_;
$self->{insertIndex} = $self->{dh}->stmt('insertIndex')
or die "No insertIndex member in BSE::DB";
+ $self->{case} eq 'controlled'
+ and die "BSE built-in searcher doesn't support controlled search (yet)";
+
my $priority = $self->{cfg}->entry("search", "index_priority", "speed");
if ($priority eq "speed") {
$self->{index} = {};
$end = $#words if $end > $#words;
for my $phrase (map { "@words[$start..$_]" } $start..$end) {
- if (lc $phrase ne $phrase && !$seen->{lc $phrase}++) {
- my $temp = $self->{index}{lc $phrase};
- if (exists $temp->{$id}) {
- $weights->{lc $phrase} *= $self->{decay_multiplier};
- $temp->{$id}[1] += $score * $weights->{lc $phrase};
- }
- else {
- $weights->{lc $phrase} = 1.0;
- $temp->{$id} = [ $sectionid, $score ];
+ if ($self->{case} eq 'context') {
+ if (lc $phrase ne $phrase && !$seen->{lc $phrase}++) {
+ my $temp = $self->{index}{lc $phrase};
+ if (exists $temp->{$id}) {
+ $weights->{lc $phrase} *= $self->{decay_multiplier};
+ $temp->{$id}[1] += $score * $weights->{lc $phrase};
+ }
+ else {
+ $weights->{lc $phrase} = 1.0;
+ $temp->{$id} = [ $sectionid, $score ];
+ }
+ $self->{index}{lc $phrase} = $temp;
}
- $self->{index}{lc $phrase} = $temp;
+ }
+ else {
+ $phrase = lc $phrase;
}
if (!$seen->{$phrase}++) {
my $temp = $self->{index}{$phrase};
use strict;
use Constants qw(:search);
-our $VERSION = "1.000";
+our $VERSION = "1.001";
use base 'BSE::Search::Base';
}
sub search {
- my ($self, $words, $section, $date, $terms, $match_all, $req) = @_;
+ my ($self, $words, $section, $date, $terms, $match_all, $req, $match_case) = @_;
# canonical form
$words =~ s/^\s+|\s+$//g;
+ $words = lc $words unless $match_case;
+
# array of [ term, unquoted, required, weight ]
my @terms;
my @exclude;
use BSE::Util::Tags qw(tag_article);
use BSE::Request;
-our $VERSION = "1.005";
+our $VERSION = "1.006";
my %actions =
(
my @terms; # terms as parsed by the search engine
my $case_sensitive;
if (defined $words && length $words) {
- $case_sensitive = $words ne lc $words;
- @results = getSearchResult($req, $words, $section, $date, \@terms, $match_all);
+ my $case = $cfg->entry('search', 'case_sensitive', 'context');
+ if ($case eq 'context') {
+ $case_sensitive = $words ne lc $words;
+ }
+ elsif ($case eq 'controlled') {
+ $case_sensitive = $cfg->param('c') || 0;
+ }
+ else {
+ $case_sensitive = 0;
+ }
+ @results = getSearchResult($req, $words, $section, $date, \@terms, $match_all,
+ $case_sensitive);
}
else {
$words = ''; # so we don't return junk for the form default
}
sub getSearchResult {
- my ($req, $words, $section, $date, $terms, $match_all) = @_;
+ my ($req, $words, $section, $date, $terms, $match_all, $match_case) = @_;
my $cfg = $req->cfg;
my $searcher_class = $cfg->entry('search', 'searcher', 'BSE::Search::BSE');
(my $searcher_file = $searcher_class . '.pm') =~ s!::!/!g;;
require $searcher_file;
- my $searcher = $searcher_class->new(cfg => $cfg);
- return $searcher->search($words, $section, $date, $terms, $match_all, $req);
+ my $case_sensitivity = $cfg->entry('search', 'case_sensitive', 'context');
+ my $searcher = $searcher_class->new(cfg => $cfg, case => $case_sensitivity);
+ return $searcher->search($words, $section, $date, $terms, $match_all, $req, $match_case);
}
my %gens;
Articles with a higher level than this are indexed as their ancestor.
Default: C<$SEARCH_LEVEL> which defaults to 5.
+=item case_sensitive
+
+Level of case-sensitivity in the search engine. This can be one of:
+
+=over
+
+=item *
+
+C<none> - no case-sensitive searches
+
+=item *
+
+C<context> - case-sensitive if there are any upper-case characters in
+the search string, case-insensitive otherwise.
+
+=item *
+
+C<controlled> - case-sensitive via a query parameter. This is
+currently not supported by the built-in search engie.
+
+=back
+
+Renegerate your search indexes after changing this value. Default:
+context.
+
=back
=head2 [search highlight]