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

Last change on this file since 12625 was 12408, checked in by mdewsnip, 18 years ago

Added a "-filter" option which can currently be used for specifying range filters (eg. we're going to use it for dates). Many thanks to Me and DL Consulting Ltd.

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