[8520] | 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 | }
|
---|
| 34 |
|
---|
[12373] | 35 | use strict;
|
---|
[8520] | 36 | use util;
|
---|
| 37 |
|
---|
| 38 |
|
---|
[12373] | 39 | my $PROGNAME = $0;
|
---|
| 40 | $PROGNAME =~ s/^.*\/(.*)$/$1/;
|
---|
[8520] | 41 |
|
---|
| 42 |
|
---|
| 43 | sub open_java_lucene
|
---|
| 44 | {
|
---|
[12275] | 45 | my $full_indexdir = shift(@_);
|
---|
[12373] | 46 | my $fuzzy = shift(@_);
|
---|
[12408] | 47 | my $filter_string = shift(@_);
|
---|
[12373] | 48 | my $sort_field = shift(@_);
|
---|
| 49 | my $dco = shift(@_);
|
---|
| 50 | my $out_file = shift(@_);
|
---|
[12364] | 51 |
|
---|
[12373] | 52 | my $classpath = &util::filename_cat($ENV{'GSDLHOME'}, "bin", "java", "LuceneWrap.jar");
|
---|
[12258] | 53 | my $java_lucene = "java -classpath \"$classpath\" org.nzdl.gsdl.LuceneWrap.GS2LuceneQuery";
|
---|
[8520] | 54 |
|
---|
[12373] | 55 | my $cmd = "| " . $java_lucene . " \"" . $full_indexdir . "\"";
|
---|
| 56 | if (defined($fuzzy)) {
|
---|
| 57 | $cmd .= " -fuzzy";
|
---|
[9219] | 58 | }
|
---|
[12408] | 59 | if (defined($filter_string)) {
|
---|
| 60 | $cmd .= " -filter \"" . $filter_string . "\"";
|
---|
| 61 | }
|
---|
[12373] | 62 | if (defined($sort_field)) {
|
---|
[12364] | 63 | $cmd .= " -sort " . $sort_field;
|
---|
[12373] | 64 | }
|
---|
| 65 | if (defined($dco)) {
|
---|
[12364] | 66 | $cmd .= " -dco " . $dco;
|
---|
[12373] | 67 | }
|
---|
| 68 | if (defined($out_file)) {
|
---|
| 69 | $cmd .= " > \"" . $out_file . "\"";
|
---|
| 70 | }
|
---|
| 71 | # print STDERR $cmd . "\n";
|
---|
[12364] | 72 |
|
---|
| 73 | if (!open (PIPEOUT, $cmd)) {
|
---|
[12373] | 74 | die "$PROGNAME - couldn't run $cmd\n";
|
---|
[8520] | 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | sub close_java_lucene
|
---|
| 79 | {
|
---|
| 80 | close(PIPEOUT);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | sub main
|
---|
| 84 | {
|
---|
| 85 | my (@argv) = @_;
|
---|
| 86 | my $argc = scalar(@argv);
|
---|
[12373] | 87 | if ($argc == 0) {
|
---|
[12408] | 88 | print STDERR "Usage: $PROGNAME full-index-dir [query] [-fuzzy] [-filter filter_string] [-sort sort_field] [-dco AND|OR] [-out out_file]\n";
|
---|
[12373] | 89 | exit 1;
|
---|
| 90 | }
|
---|
[8520] | 91 |
|
---|
[12373] | 92 | my $full_indexdir = shift(@argv);
|
---|
[8520] | 93 | my $query = undef;
|
---|
[12373] | 94 | my $fuzzy = undef;
|
---|
[12408] | 95 | my $filter_string = undef;
|
---|
[12275] | 96 | my $sort_field = undef;
|
---|
[12373] | 97 | my $dco = undef;
|
---|
[9219] | 98 | my $out_file = undef;
|
---|
[12373] | 99 | for (my $i = 0; $i < scalar(@argv); $i++)
|
---|
| 100 | {
|
---|
| 101 | if ($argv[$i] eq "-fuzzy") {
|
---|
| 102 | $fuzzy = 1;
|
---|
| 103 | }
|
---|
[12408] | 104 | elsif ($argv[$i] eq "-filter") {
|
---|
| 105 | $i++;
|
---|
| 106 | $filter_string = $argv[$i];
|
---|
| 107 | }
|
---|
[12373] | 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 | }
|
---|
[8520] | 123 | }
|
---|
| 124 |
|
---|
[12408] | 125 | open_java_lucene($full_indexdir, $fuzzy, $filter_string, $sort_field, $dco, $out_file);
|
---|
[12373] | 126 |
|
---|
[8520] | 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);
|
---|