source: gs3-extensions/solr/trunk/src/perllib/solrutil.pm@ 29711

Last change on this file since 29711 was 29711, checked in by ak19, 9 years ago

Moving from using the solr jetty server to solr using the GS3 tomcat server. Now localhost:8383/solr hosts the solr server RESTful pages. Changes: 1. Minor changes to GS3 build.xml. 2. GLI no longer does the temporary stopping of the GS3 server, launching jetty server for building a solr collection, stopping jetty, restarting GS3 tomcat server. GLI leaves the GS3 server running. 3. The main changes are to ext/solr. The ext/solr/gs3-setup.sh sets the new SOLR_PORT and SOLR_HOST variables read from the GS3 build.properties, as the jetty port and host variables are no longer used. ext/solr/build.xml now puts the solr war file into tomcat's webapps, as well as helper libraries necessary (xalan related); a solr.xml context file is created from a template file and placed into tomcat's conf/Catalina/localhost; additional solr jar files are copied into tomcat/lib, as well as the slf4j bridge being copied into GS3/web/WEB-INF/lib; the solr perl code has been changed to use the new RESTful URLs and particularly to work with solr running off the GS3 tomcat server, or stop and start it as required, rather than working with (or stopping and starting) the solr jetty server. A new run_solr_server.pl executable script runs the tomcat server rather than the jetty server; major changes to the Java Solr code to no longer work with the EmbeddedSolrServer (which caused a conflict when the index is accessed by solr jetty server upon rebuild of solr collections), our solr Java code now uses HttpSolrServer to contact the solr servlet running off tomcat. 5. Still a bug: when search results go over a page after rebuilding a solr collection in GLI against a running GS3 server, the 2nd page of search results aren't present and things break. But if the server is not running, solr collections rebuild fine, so the changes do everything that GS3.06 did and more.

File size: 2.8 KB
Line 
1###########################################################################
2#
3# solrutil.pm -- support module for Solr extension
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package solrutil;
27
28use strict;
29
30sub locate_file
31{
32 my ($search_path,$suffix) = @_;
33
34 foreach my $sp (@$search_path) {
35 my $full_path = &util::filename_cat($sp,$suffix);
36
37 if (-f $full_path) {
38 return $full_path;
39 }
40 }
41
42 # if get to here, then failed to find match
43
44 print STDERR "Error: Failed to find '$suffix'\n";
45 print STDERR " Looked in: ", join(", ", @$search_path), "\n";
46 exit -1;
47}
48
49
50sub get_search_path
51{
52 my $search_path = [];
53
54 push(@$search_path,$ENV{'GSDLCOLLECTDIR'}) if defined $ENV{'GSDLCOLLECTDIR'};
55 push(@$search_path,$ENV{'GSDLHOME'}) if defined $ENV{'GSDLHOME'};
56 push(@$search_path,$ENV{'GEXT_SOLR'}) if defined $ENV{'GEXT_SOLR'};
57
58 return $search_path;
59}
60
61
62
63sub open_post_pipe
64{
65 my ($core) = @_;
66
67 my $search_path = get_search_path();
68
69 chdir($ENV{'GEXT_SOLR'});
70
71 my $post_jar = &util::filename_cat("lib","java","solr-post.jar");
72 my $full_post_jar = solrutil::locate_file($search_path,$post_jar);
73
74 my $server_port = $ENV{'SOLR_PORT'}; # tomcat
75 my $server_host = $ENV{'SOLR_HOST'};
76
77 # Now run solr-post command
78 my $post_props = "-Durl=http://$server_host:$server_port/solr/$core/update";
79 $post_props .= " -Ddata=stdin";
80 $post_props .= " -Dcommit=yes";
81
82 my $post_java_cmd = "java -Xmx256M $post_props -jar \"$full_post_jar\"";
83
84 ##print STDERR "**** post cmd = $post_java_cmd\n";
85
86 open (PIPEOUT, "| $post_java_cmd")
87 || die "Error in solr_passes.pl: Failed to run $post_java_cmd\n!$\n";
88
89}
90
91sub print_to_post_pipe
92{
93 my ($line) = @_;
94
95 print PIPEOUT $line;
96}
97
98sub close_post_pipe
99{
100 # closing the pipe has the effect of shutting down solr-post.jar
101 close(PIPEOUT);
102}
103
1041;
Note: See TracBrowser for help on using the repository browser.