FAQ-OMatic
view release on metacpan or search on metacpan
lib/FAQ/OMatic/SearchMod.pm view on Meta::CPAN
$pattern = nkf('-e', $pattern);
}
my @patternwords = FAQ::OMatic::Words::getWords( $pattern );
$params->{'_searchArray'} = \@patternwords;
}
sub addNewFiles {
my $wordset = shift; #ary ref
my $fileset = shift; # hash ref -- where to add results
my $words = {};
# Get the list of files touched since last searchDB build
if (not open HINTS, "<$FAQ::OMatic::Config::metaDir/searchHints") {
# sorry, can't help ya
return;
}
my @touchedFiles = <HINTS>;
close HINTS;
# index each item
my $filename;
my $item;
foreach $filename (@touchedFiles) {
chomp $filename;
$item = new FAQ::OMatic::Item($filename);
$item->extractWords($words);
}
# for every word in the wordset, add all the files it appears
# in to the fileset passed to us.
my $word;
foreach $word (@{$wordset}) {
if ($words->{$word}) {
foreach $filename (keys %{$words->{$word}}) {
$fileset->{$filename} = 1;
}
}
}
# notice that if there were suffixes of the user's requested words
# in the new content that weren't in the system anywhere when the
# searchDB was built, then those suffixes won't be in the wordset,
# and the search will miss them. Hey, wah, this is better than
# missing ALL the new content, okay? :v)
# this also screws up the counts of how many matches this file
# had (since it could contribute matches from the searchDB lookup
# AND the newFiles lookup), so I'm going to leave it turned off
# for now. Rats.
}
sub getRecentSet {
my $params = shift;
my $recentList = [];
my $durationdays = $params->{'_duration'};
# used directly to compare against perl's floating-point -M file test
my $then = time() - $durationdays*24*60*60;
# Used to compare against LastModifiedSecs field.
# By 'days' we mean 24-hour periods, not calendar days.
# (In the US, for example, there is a 23-hour calendar day in
# April and a 25-hour one in the fall, what, in October? for daylight
# savings time.)
my $filei;
foreach $filei (FAQ::OMatic::getAllItemNames()) {
# use file time as a hint for which items we even need to open up.
next if (-M "$FAQ::OMatic::Config::itemDir/$filei" >= $durationdays);
# ...but only trust LastModifiedSecs field for final say on mod time.
my $item = new FAQ::OMatic::Item($filei);
my $lm = $item->{'LastModifiedSecs'} || 0;
if ($lm > $then) {
push @{$recentList}, $filei;
}
}
return $recentList;
}
# reasonable text for 'n' days
my %dayMap = (
0 => gettext("zero days"),
1 => gettext("day"),
2 => gettext("two days"),
7 => gettext("week"),
14 => gettext("fortnight"),
31 => gettext("month"), # (31? a month, give or take. :v)
92 => gettext("three months"),
184 => gettext("six months"),
366 => gettext("year")
);
sub getRecentMap {
# get a copy of the day map (except for 0)
# for use in creating the recent form
my %recentMap = %dayMap;
delete $recentMap{0};
return \%recentMap;
}
sub textDays {
my $duration = shift || 0;
my $textDayStr = $dayMap{$duration} || $duration." ".gettext("days");
return $textDayStr;
}
1;
( run in 1.108 second using v1.01-cache-2.11-cpan-39bf76dae61 )