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 |
|
---|
29 | BEGIN {
|
---|
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 |
|
---|
38 | use util;
|
---|
39 |
|
---|
40 | sub 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 |
|
---|
52 | sub open_java_lucene
|
---|
53 | {
|
---|
54 | my ($full_indexdir, $out_file) = @_;
|
---|
55 | my $bin_java = &util::filename_cat($ENV{'GSDLHOME'},"bin","java");
|
---|
56 | my $classpath = &util::filename_cat($bin_java,"LuceneWrap.jar");
|
---|
57 |
|
---|
58 | my $java_lucene = "java -classpath $classpath GS2LuceneQuery";
|
---|
59 | my $java_cmd = "$java_lucene";
|
---|
60 |
|
---|
61 | if (defined($out_file)) {
|
---|
62 | $out_file = " > \"".$out_file. "\"";
|
---|
63 | } else {
|
---|
64 | $out_file = "";
|
---|
65 | }
|
---|
66 | if (!open (PIPEOUT, "| $java_cmd $full_indexdir $out_file")) {
|
---|
67 | die "$PROGNAME - couldn't run $java_cmd\n";
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|
71 |
|
---|
72 | sub close_java_lucene
|
---|
73 | {
|
---|
74 | close(PIPEOUT);
|
---|
75 | }
|
---|
76 |
|
---|
77 | sub main
|
---|
78 | {
|
---|
79 | my (@argv) = @_;
|
---|
80 | my $argc = scalar(@argv);
|
---|
81 |
|
---|
82 | my $full_indexdir;
|
---|
83 | my $query = undef;
|
---|
84 | my $out_file = undef;
|
---|
85 | if ($argc==1) {
|
---|
86 | $full_indexdir = $argv[0];
|
---|
87 | }
|
---|
88 | elsif ($argc==2) {
|
---|
89 | $full_indexdir = $argv[0];
|
---|
90 | $query = $argv[1];
|
---|
91 | }
|
---|
92 | elsif ($argc==3) {
|
---|
93 | $full_indexdir = $argv[0];
|
---|
94 | $query = $argv[1];
|
---|
95 | $out_file = $argv[2];
|
---|
96 | }
|
---|
97 | else {
|
---|
98 | print STDERR "Usage: $PROGNAME full-index-dir [query] [outfile]\n";
|
---|
99 | exit 1;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | open_java_lucene($full_indexdir, $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 |
|
---|