Add entries_cache_meta to general.
[blosxom-plugins.git] / general / lucene
blobe589f470cc84aa1796443401cfa3f91113f2f3dd
1 # Blosxom Plugin: lucene
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 #            and Sam Ruby <rubys@intertwingly.net>
4 # Version: 2.0b2
5 # Documentation: See the bottom of this file or type: perldoc lucene
7 package lucene;
9 # --- Configurable variables -----
11 # Turn on the Lucene engine (set to 1 only once the other bits are in place)?
12 my $lucene_on = 0;
14 # Where's Java?
15 my $JAVA_HOME = '/path/to/j2sdk1.3.1/';
17 # Where's lucene?
18 my $lucene = '/path/to/lib/java/*.jar';
20 # What's my index?
21 my $index = '/Library/WebServer/Data/lucene';
23 # --------------------------------
25 $search;
27 use CGI qw/:standard/;
28 use File::stat;
29 use URI::Escape;
30 use POSIX qw(strftime);
31 use Env qw(@PATH @CLASSPATH);
33 unshift @PATH, "$JAVA_HOME/bin";
34 push @CLASSPATH, "$JAVA_HOME/lib/tools.jar";
35 push @CLASSPATH, "$JAVA_HOME/jre/lib/rt.jar";
36 push @CLASSPATH, "/any/other/appropriate/java/lib";
37 push @CLASSPATH, glob($lucene);
39 sub start {
40   $lucene_on or return 0;
41   $blosxom::static_or_dynamic eq 'dynamic' or return 0;
42   param('q') or return 0;
43   $search = "Search results for: " . param('q');
44   1;
47 sub entries {
48   return sub {
49     my(%files, %indexes);
51     my $query = uri_escape(param('q'));
52     $query =~ s/;//g;
53   
54     # Take a gander at what Lucene came up with based upon the search criteria
55     foreach (`$JAVA_HOME/bin/java -cp $ENV{CLASSPATH} LuceneSearch $index $query`) {
56       chomp;
57       s!\./!!;
58       $_ =~ /\.txt$/ and $files{"$blosxom::datadir/$_"} = stat("$blosxom::datadir/$_")->mtime;
59     }       
60   
61     return (\%files, \%indexes);
62   };
67 __END__
69 =head1 NAME
71 Blosxom Plug-in: lucene
73 =head1 SYNOPSIS
75 Based upon: http://radio.weblogs.com/0101679/stories/2002/08/13/luceneSearchFromBlosxom.html
77 Purpose: Lucene [http://jakarta.apache.org/lucene/] is a fabulous
78 text search engine written in Java.  This plug-in hooks in the results
79 of a Lucene search, displaying only the stories matching the search query
80 (as specified by ?q=keywords).
82 Populates $lucene::search with "Search results for: keywords" for use in
83 flavour templates.
85 Replaces the default $blosxom::entries subroutine.  You'd best put it before
86 any other plug-ins that override the default $blosxom::entries subroutine.  
87 When ?q=keywords turns on the lucene plug-in, it'll then be used instead of
88 whatever other entries overrides you have down the chain.  
90 E.g. My setup is as follows:
92 01lucene
94 02entries_index
96 other
98 plugins
100 follow
102 This plug-in could be used as a template for hooking into just about any
103 files-based text search engine.
105 =head1 VERSION
107 2.0b1
109 Version number coincides with the version of Blosxom with which the 
110 current version was first bundled.
112 =head1 AUTHOR
114 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
116 This plugin is now maintained by the Blosxom Sourceforge Team,
117 <blosxom-devel@lists.sourceforge.net>.
119 =head1 SEE ALSO
121 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
123 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
125 =head1 BUGS
127 None known; please send bug reports and feedback to the Blosxom
128 development mailing list <blosxom-devel@lists.sourceforge.net>.
130 =head1 LICENSE
132 Blosxom and this Blosxom Plug-in
133 Copyright 2003, Rael Dornfest 
135 Permission is hereby granted, free of charge, to any person obtaining a
136 copy of this software and associated documentation files (the "Software"),
137 to deal in the Software without restriction, including without limitation
138 the rights to use, copy, modify, merge, publish, distribute, sublicense,
139 and/or sell copies of the Software, and to permit persons to whom the
140 Software is furnished to do so, subject to the following conditions:
142 The above copyright notice and this permission notice shall be included
143 in all copies or substantial portions of the Software.
145 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
146 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
147 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
148 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
149 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
150 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
151 OTHER DEALINGS IN THE SOFTWARE.