source: trunk/gsdl/bin/script/lucene_query.pl@ 12290

Last change on this file since 12290 was 12275, checked in by mdewsnip, 18 years ago

Added a command-line option for sorting the search results.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# lucene_query.pl -- perl wrapper to initiate query using Lucene
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28
29BEGIN {
30 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
31 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
32 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
33 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
34 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
36}
37
38use util;
39
40sub full_indexdir
41{
42 my ($col_name,$indexdir) = @_;
43
44 my $full_indexdir
45 = &util::filename_cat($ENV{'GSDLHOME'},"collect",$col_name,"index",
46 $indexdir);
47
48 return $full_indexdir;
49}
50
51
52sub open_java_lucene
53{
54 my $full_indexdir = shift(@_);
55 my $sort_field = shift(@_) || "";
56 my $out_file = shift(@_);
57 my $bin_java = &util::filename_cat($ENV{'GSDLHOME'},"bin","java");
58 my $classpath = &util::filename_cat($bin_java,"LuceneWrap.jar");
59
60 my $java_lucene = "java -classpath \"$classpath\" org.nzdl.gsdl.LuceneWrap.GS2LuceneQuery";
61 my $java_cmd = "$java_lucene";
62
63 if (defined($out_file)) {
64 $out_file = " > \"".$out_file. "\"";
65 } else {
66 $out_file = "";
67 }
68 if (!open (PIPEOUT, "| $java_cmd \"$full_indexdir\" $sort_field")) {
69 die "$PROGNAME - couldn't run $java_cmd\n";
70 }
71}
72
73sub close_java_lucene
74{
75 close(PIPEOUT);
76}
77
78sub main
79{
80 my (@argv) = @_;
81 my $argc = scalar(@argv);
82
83 my $full_indexdir;
84 my $query = undef;
85 my $sort_field = undef;
86 my $out_file = undef;
87 if ($argc == 0) {
88 print STDERR "Usage: $PROGNAME full-index-dir [query] [sort_field] [outfile]\n";
89 exit 1;
90 }
91 if ($argc >= 1) {
92 $full_indexdir = $argv[0];
93 }
94 if ($argc >= 2) {
95 $query = $argv[1];
96 }
97 if ($argc >= 3) {
98 $sort_field = $argv[2];
99 }
100 if ($argc >= 4) {
101 $out_file = $argv[3];
102 }
103 open_java_lucene($full_indexdir, $sort_field, $out_file);
104
105 if (defined $query) {
106 print PIPEOUT "$query\n";
107 }
108 else {
109 while (defined (my $line = <STDIN>)) {
110 print PIPEOUT $line;
111 }
112 }
113
114 close_java_lucene();
115}
116
117$PROGNAME = $0;
118$PROGNAME =~ s/^.*\/(.*)$/$1/;
119
120&main(@ARGV);
121
Note: See TracBrowser for help on using the repository browser.