tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / general / lucene
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
6
7 package lucene;
8
9 # --- Configurable variables -----
10
11 # Turn on the Lucene engine (set to 1 only once the other bits are in place)?
12 my $lucene_on = 0;
13
14 # Where's Java?
15 my $JAVA_HOME = '/path/to/j2sdk1.3.1/';
16
17 # Where's lucene?
18 my $lucene = '/path/to/lib/java/*.jar';
19
20 # What's my index?
21 my $index = '/Library/WebServer/Data/lucene';
22
23 # --------------------------------
24
25 $search;
26
27 use CGI qw/:standard/;
28 use File::stat;
29 use URI::Escape;
30 use POSIX qw(strftime);
31 use Env qw(@PATH @CLASSPATH);
32
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);
38
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;
45 }
46
47 sub entries {
48   return sub {
49     my(%files, %indexes);
50
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   };
63 }
64
65 1;
66
67 __END__
68
69 =head1 NAME
70
71 Blosxom Plug-in: lucene
72
73 =head1 SYNOPSIS
74
75 Based upon: http://radio.weblogs.com/0101679/stories/2002/08/13/luceneSearchFromBlosxom.html
76
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).
81
82 Populates $lucene::search with "Search results for: keywords" for use in
83 flavour templates.
84
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.  
89
90 E.g. My setup is as follows:
91
92 01lucene
93
94 02entries_index
95
96 other
97
98 plugins
99
100 follow
101
102 This plug-in could be used as a template for hooking into just about any
103 files-based text search engine.
104
105 =head1 VERSION
106
107 2.0b1
108
109 Version number coincides with the version of Blosxom with which the 
110 current version was first bundled.
111
112 =head1 AUTHOR
113
114 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
115
116 This plugin is now maintained by the Blosxom Sourceforge Team,
117 <blosxom-devel@lists.sourceforge.net>.
118
119 =head1 SEE ALSO
120
121 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
122
123 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
124
125 =head1 BUGS
126
127 None known; please send bug reports and feedback to the Blosxom
128 development mailing list <blosxom-devel@lists.sourceforge.net>.
129
130 =head1 LICENSE
131
132 Blosxom and this Blosxom Plug-in
133 Copyright 2003, Rael Dornfest 
134
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:
141
142 The above copyright notice and this permission notice shall be included
143 in all copies or substantial portions of the Software.
144
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.