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

Last change on this file since 12656 was 12656, checked in by mdewsnip, 17 years ago

Put old range filter stuff back, and added "-startresults" and "-endresults" support to return just the desired results, thus speeding up the query result parsing. Many thanks to John Thompson and DL Consulting Ltd.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.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}
34
35use strict;
36use util;
37
38
39my $PROGNAME = $0;
40$PROGNAME =~ s/^.*\/(.*)$/$1/;
41
42
43sub open_java_lucene
44{
45 my $full_indexdir = shift(@_);
46 my $fuzzy = shift(@_);
47 my $filter_string = shift(@_);
48 my $sort_field = shift(@_);
49 my $dco = shift(@_);
50 my $start_results = shift(@_);
51 my $end_results = shift(@_);
52 my $out_file = shift(@_);
53
54 my $classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "LuceneWrap.jar");
55 my $java_lucene = "java -classpath \"$classpath\" org.nzdl.gsdl.LuceneWrap.GS2LuceneQuery";
56
57 my $cmd = "| " . $java_lucene . " \"" . $full_indexdir . "\"";
58 if (defined($fuzzy)) {
59 $cmd .= " -fuzzy";
60 }
61 if (defined($filter_string)) {
62 $cmd .= " -filter \"" . $filter_string . "\"";
63 }
64 if (defined($sort_field)) {
65 $cmd .= " -sort " . $sort_field;
66 }
67 if (defined($dco)) {
68 $cmd .= " -dco " . $dco;
69 }
70 if (defined($start_results)) {
71 $cmd .= " -startresults " . $start_results;
72 }
73 if (defined($end_results)) {
74 $cmd .= " -endresults " . $end_results;
75 }
76 if (defined($out_file)) {
77 $cmd .= " > \"" . $out_file . "\"";
78 }
79 # print STDERR $cmd . "\n";
80
81 if (!open (PIPEOUT, $cmd)) {
82 die "$PROGNAME - couldn't run $cmd\n";
83 }
84}
85
86sub close_java_lucene
87{
88 close(PIPEOUT);
89}
90
91sub main
92{
93 my (@argv) = @_;
94 my $argc = scalar(@argv);
95 if ($argc == 0) {
96 print STDERR "Usage: $PROGNAME full-index-dir [query] [-fuzzy] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-startresults number -endresults number] [-out out_file]\n";
97 exit 1;
98 }
99
100 my $full_indexdir = shift(@argv);
101 my $query = undef;
102 my $fuzzy = undef;
103 my $filter_string = undef;
104 my $sort_field = undef;
105 my $dco = undef;
106 my $start_results = undef;
107 my $end_results = undef;
108 my $out_file = undef;
109 for (my $i = 0; $i < scalar(@argv); $i++)
110 {
111 if ($argv[$i] eq "-fuzzy") {
112 $fuzzy = 1;
113 }
114 elsif ($argv[$i] eq "-filter") {
115 $i++;
116 $filter_string = $argv[$i];
117 }
118 elsif ($argv[$i] eq "-sort") {
119 $i++;
120 $sort_field = $argv[$i];
121 }
122 elsif ($argv[$i] eq "-dco") {
123 $i++;
124 $dco = $argv[$i];
125 }
126 elsif ($argv[$i] eq "-startresults") {
127 $i++;
128 $start_results = $argv[$i];
129 }
130 elsif ($argv[$i] eq "-endresults") {
131 $i++;
132 $end_results = $argv[$i];
133 }
134 elsif ($argv[$i] eq "-out") {
135 $i++;
136 $out_file = $argv[$i];
137 }
138 else {
139 $query = $argv[$i];
140 }
141 }
142
143 open_java_lucene($full_indexdir, $fuzzy, $filter_string, $sort_field, $dco, $start_results, $end_results, $out_file);
144
145 if (defined $query) {
146 print PIPEOUT "$query\n";
147 }
148 else {
149 while (defined (my $line = <STDIN>)) {
150 print PIPEOUT $line;
151 }
152 }
153
154 close_java_lucene();
155}
156
157&main(@ARGV);
Note: See TracBrowser for help on using the repository browser.