diff options
author | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-06-25 16:00:32 +0800 |
---|---|---|
committer | in2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2003-06-25 16:00:32 +0800 |
commit | d5c1e17d4914c8409a7a741570e94e0ade6ec017 (patch) | |
tree | 3c1b5d165e5321365cf9e14b874c2bd745ec7d9b /blog | |
parent | 8b95b780207789b0b5531429ee07027ab9ea85e2 (diff) | |
download | pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.tar pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.tar.gz pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.tar.bz2 pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.tar.lz pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.tar.xz pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.tar.zst pttbbs-d5c1e17d4914c8409a7a741570e94e0ade6ec017.zip |
FuzzyIndex
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@966 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'blog')
-rwxr-xr-x | blog/blog.pl | 17 | ||||
-rwxr-xr-x | blog/builddb.pl | 16 |
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($$$$$) |