summaryrefslogtreecommitdiffstats
path: root/blog
diff options
context:
space:
mode:
Diffstat (limited to 'blog')
-rwxr-xr-xblog/blog.pl17
-rwxr-xr-xblog/builddb.pl16
2 files changed, 28 insertions, 5 deletions
diff --git a/blog/blog.pl b/blog/blog.pl
index 96c929af..515c1e65 100755
--- a/blog/blog.pl
+++ b/blog/blog.pl
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $Id: blog.pl,v 1.23 2003/06/19 13:06:58 in2 Exp $
+# $Id: blog.pl,v 1.24 2003/06/25 08:00:32 in2 Exp $
use CGI qw/:standard/;
use lib qw/./;
use LocalVars;
@@ -9,6 +9,7 @@ use Data::Dumper;
use Date::Calc qw(:all);
use Template;
use HTML::Calendar::Simple;
+use OurNet::FuzzyIndex;
use vars qw/@emonth @cnumber %config %attr %article %th/;
@@ -69,6 +70,15 @@ sub main
$ptr);
}
}
+ elsif( $attr{"$fn.loadBlog"} =~ /FuzzySearch/i ){
+ my $idx = OurNet::FuzzyIndex->new("$BLOGDATA/$brdname.idx");
+ my %result = $idx->query($th{SearchKey} = param('SearchKey'),
+ MATCH_FUZZY);
+ foreach my $t (sort { $result{$b} <=> $result{$a} } keys(%result)) {
+ AddArticle('blog', $attr{"$fn.loadBlogFields"},
+ $idx->getkey($t), sprintf("%5.1f", $result{$t} / 10));
+ }
+ }
if( $attr{"$fn.loadBlogPrevNext"} ){
my $s = packdate($y, $m, $d);
@@ -225,9 +235,9 @@ sub main
print "<pre>template error: ". $tmpl->error();
}
-sub AddArticle($$$)
+sub AddArticle($$$;$)
{
- my($cl, $fields, $s) = @_;
+ my($cl, $fields, $s, $score) = @_;
my($content, $short) = ();
$content = applyfilter($article{"$s.content"}, $config{outputfilter})
if( $fields =~ /content/i );
@@ -248,6 +258,7 @@ sub AddArticle($$$)
author => (($fields !~ /author/i) ? '' :
$article{"$s.author"}),
short => $short,
+ score => $score,
}
if( $article{"$s.title"} );
}
diff --git a/blog/builddb.pl b/blog/builddb.pl
index b519587b..1cec2615 100755
--- a/blog/builddb.pl
+++ b/blog/builddb.pl
@@ -7,6 +7,7 @@ use IO::Handle;
use Data::Dumper;
use BBSFileHeader;
use DB_File;
+use OurNet::FuzzyIndex;
sub main
{
@@ -99,12 +100,17 @@ sub buildconfigure($$)
sub builddata($$$$$$)
{
my($board, $rbh, $rebuild, $contentonly, $number, $force) = @_;
- my(%dat, $dbfn, $y, $m, $d, $t, $currid);
+ my(%dat, $dbfn, $idxfn, $y, $m, $d, $t, $currid, $idx);
$dbfn = "$BLOGROOT/$board.db";
- unlink $dbfn if( $rebuild );
+ $idxfn = "$BLOGROOT/$board.idx";
+ if( $rebuild ){
+ unlink $dbfn;
+ unlink $idxfn;
+ }
tie %dat, 'DB_File', $dbfn, O_CREAT | O_RDWR, 0666, $DB_HASH;
+ $idx = OurNet::FuzzyIndex->new($idxfn);
foreach( $number ? $number : (1..($rbh->{num} - 1)) ){
if( !(($y, $m, $d, $t) =
$rbh->{"$_.title"} =~ /(\d+)\.(\d+).(\d+),(.*)/) ){
@@ -127,6 +133,9 @@ sub builddata($$$$$$)
$dat{"$currid.content"} = $rbh->{"$_.content"});
$dat{"$currid.short"} = ("$c[0]\n$c[1]\n$c[2]\n$c[3]\n");
+ $idx->delete($currid) if( $idx->findkey($currid) );
+ $idx->insert($currid, $rbh->{"$_.content"});
+
if( !$contentonly ){
debugmsg("\tbuilding $currid linking... ");
if( $dat{$currid} ){
@@ -163,6 +172,9 @@ sub builddata($$$$$$)
}
}
untie %dat;
+ $idx->sync();
+ undef $idx;
+ chmod 0666, $idxfn;
}
sub getdir($$$$$)