sunspot_solr-xaop 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,24 @@
1
+ = Sunspot::Solr
2
+
3
+ Sunspot::Solr is a packaged distribution of Solr for use with the
4
+ Sunspot[http://outoftime.github.com/sunspot] and
5
+ Sunspot::Rails[https://github.com/outoftime/sunspot/tree/master/sunspot_rails]
6
+ gems. See those gems' documentation for more information.
7
+
8
+ == Installation
9
+
10
+ gem install sunspot_solr
11
+
12
+ In order to start the daemon, run:
13
+
14
+ sunspot-solr start -- [-d /path/to/data/directory] [-p port] [-s path/to/solr/home] [--pid-dir=path/to/pid/dir]
15
+
16
+ If you don't specify a data directory, your Solr index will be stored in your
17
+ operating system's temporary directory.
18
+
19
+ If you specify a solr home, the directory must contain a <code>conf</code>
20
+ directory, which should contain at least <code>schema.xml</code> and
21
+ <code>solrconfig.xml</code>. Be sure to copy the <code>schema.xml</code> out of
22
+ the Sunspot gem's <code>solr/solr/conf</code> directory. Sunspot relies on the
23
+ field name patterns defined in the packaged <code>schema.xml</code>, so those
24
+ cannot be modified.
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'fileutils'
4
+ require 'tempfile'
5
+ require 'tmpdir'
6
+ require 'optparse'
7
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'solr', 'server')
8
+ rescue LoadError => e
9
+ if require 'rubygems'
10
+ retry
11
+ else
12
+ raise(e)
13
+ end
14
+ end
15
+
16
+ server = Sunspot::Solr::Server.new
17
+
18
+ OptionParser.new do |opts|
19
+ opts.banner = "Usage: sunspot-solr start [options]"
20
+
21
+ opts.on '-p', '--port=PORT', 'Port on which to run Solr (default 8983)' do |p|
22
+ server.port = p
23
+ end
24
+
25
+ opts.on '-d', '--data-directory=DIRECTORY', 'Solr data directory' do |d|
26
+ server.solr_data_dir = File.expand_path(d)
27
+ end
28
+
29
+ opts.on '-s', '--solr-home=HOME', 'Solr home directory (should contain conf/ directory)' do |s|
30
+ server.solr_home = File.expand_path(s)
31
+ end
32
+
33
+ opts.on '-j', '--solr-jar=JAR', 'Solr start jar' do |j|
34
+ server.solr_jar = File.expand_path(j)
35
+ end
36
+
37
+ opts.on '--pid-dir=PID_DIR', 'Directory for pid files' do |pd|
38
+ server.pid_dir = File.expand_path(pd)
39
+ end
40
+
41
+ opts.on '-l', '--log-level=LOG_LEVEL', 'Solr logging level' do |l|
42
+ server.log_level = l
43
+ end
44
+
45
+ opts.on '--log-file=LOG_FILE', 'Path to Solr log file' do |lf|
46
+ server.log_file = File.expand_path(lf)
47
+ end
48
+
49
+ opts.on '--max-memory=MEMORY', 'Specify the maximum size of the memory allocation pool' do |mm|
50
+ server.max_memory = mm
51
+ end
52
+
53
+ opts.on '--min-memory=MEMORY', 'Specify the initial size of the memory allocation pool' do |mm|
54
+ server.min_memory = mm
55
+ end
56
+ end.parse!
57
+
58
+ begin
59
+ case ARGV[0]
60
+ when 'start'
61
+ server.start
62
+ when 'run'
63
+ server.run
64
+ when 'stop'
65
+ server.stop
66
+ when 'restart'
67
+ server.stop
68
+ server.start
69
+ else
70
+ abort("Usage: sunspot-solr (start|stop|run)")
71
+ end
72
+ rescue Sunspot::Solr::Server::ServerError => e
73
+ abort(e.message)
74
+ end
@@ -0,0 +1,171 @@
1
+ require 'escape'
2
+ require 'set'
3
+ require 'tempfile'
4
+ require 'sunspot/java'
5
+
6
+ module Sunspot
7
+ module Solr
8
+ class Server #:nodoc:
9
+ # Raised if #stop is called but the server is not running
10
+ ServerError = Class.new(RuntimeError)
11
+ AlreadyRunningError = Class.new(ServerError)
12
+ NotRunningError = Class.new(ServerError)
13
+ JavaMissing = Class.new(ServerError)
14
+
15
+ # Name of the sunspot executable (shell script)
16
+ SOLR_START_JAR = File.expand_path(
17
+ File.join(File.dirname(__FILE__), '..', '..', '..', 'solr', 'start.jar')
18
+ )
19
+
20
+ LOG_LEVELS = Set['SEVERE', 'WARNING', 'INFO', 'CONFIG', 'FINE', 'FINER', 'FINEST']
21
+
22
+ attr_accessor :min_memory, :max_memory, :port, :solr_data_dir, :solr_home, :log_file
23
+ attr_writer :pid_dir, :pid_file, :log_level, :solr_data_dir, :solr_home, :solr_jar
24
+
25
+ def initialize(*args)
26
+ ensure_java_installed
27
+ super(*args)
28
+ end
29
+
30
+ #
31
+ # Start the sunspot-solr server. Bootstrap solr_home first,
32
+ # if neccessary.
33
+ #
34
+ # ==== Returns
35
+ #
36
+ # Boolean:: success
37
+ #
38
+ def start
39
+ if File.exist?(pid_path)
40
+ existing_pid = IO.read(pid_path).to_i
41
+ begin
42
+ Process.kill(0, existing_pid)
43
+ raise(AlreadyRunningError, "Server is already running with PID #{existing_pid}")
44
+ rescue Errno::ESRCH
45
+ STDERR.puts("Removing stale PID file at #{pid_path}")
46
+ FileUtils.rm(pid_path)
47
+ end
48
+ end
49
+ fork do
50
+ pid = fork do
51
+ Process.setsid
52
+ STDIN.reopen('/dev/null')
53
+ STDOUT.reopen('/dev/null', 'a')
54
+ STDERR.reopen(STDOUT)
55
+ run
56
+ end
57
+ FileUtils.mkdir_p(pid_dir)
58
+ File.open(pid_path, 'w') do |file|
59
+ file << pid
60
+ end
61
+ end
62
+ end
63
+
64
+ #
65
+ # Run the sunspot-solr server in the foreground. Boostrap
66
+ # solr_home first, if neccessary.
67
+ #
68
+ # ==== Returns
69
+ #
70
+ # Boolean:: success
71
+ #
72
+ def run
73
+ command = ['java']
74
+ command << "-Xms#{min_memory}" if min_memory
75
+ command << "-Xmx#{max_memory}" if max_memory
76
+ command << "-Djetty.port=#{port}" if port
77
+ command << "-Dsolr.data.dir=#{solr_data_dir}" if solr_data_dir
78
+ command << "-Dsolr.solr.home=#{solr_home}" if solr_home
79
+ command << "-Djava.util.logging.config.file=#{logging_config_path}" if logging_config_path
80
+ command << '-jar' << File.basename(solr_jar)
81
+ FileUtils.cd(File.dirname(solr_jar)) do
82
+ exec(Escape.shell_command(command))
83
+ end
84
+ end
85
+
86
+ #
87
+ # Stop the sunspot-solr server.
88
+ #
89
+ # ==== Returns
90
+ #
91
+ # Boolean:: success
92
+ #
93
+ def stop
94
+ if File.exist?(pid_path)
95
+ pid = IO.read(pid_path).to_i
96
+ begin
97
+ Process.kill('TERM', pid)
98
+ rescue Errno::ESRCH
99
+ raise NotRunningError, "Process with PID #{pid} is no longer running"
100
+ ensure
101
+ FileUtils.rm(pid_path)
102
+ end
103
+ else
104
+ raise NotRunningError, "No PID file at #{pid_path}"
105
+ end
106
+ end
107
+
108
+ def log_level=(level)
109
+ unless LOG_LEVELS.include?(level.to_s.upcase)
110
+ raise(ArgumentError, "#{level} is not a valid log level: Use one of #{LOG_LEVELS.to_a.join(',')}")
111
+ end
112
+ @log_level = level.to_s.upcase
113
+ end
114
+
115
+ def log_level
116
+ @log_level || 'WARNING'
117
+ end
118
+
119
+ def pid_path
120
+ File.join(pid_dir, pid_file)
121
+ end
122
+
123
+ def pid_file
124
+ @pid_file || 'sunspot-solr.pid'
125
+ end
126
+
127
+ def pid_dir
128
+ File.expand_path(@pid_dir || FileUtils.pwd)
129
+ end
130
+
131
+ def solr_data_dir
132
+ File.expand_path(@solr_data_dir || Dir.tmpdir)
133
+ end
134
+
135
+ def solr_home
136
+ File.expand_path(@solr_home || File.join(File.dirname(solr_jar), 'solr'))
137
+ end
138
+
139
+ def solr_jar
140
+ @solr_jar || SOLR_START_JAR
141
+ end
142
+
143
+ private
144
+
145
+ def ensure_java_installed
146
+ unless defined?(@java_installed)
147
+ @java_installed = Sunspot::Java.installed?
148
+ unless @java_installed
149
+ raise JavaMissing.new("You need a Java Runtime Environment to run the Solr server")
150
+ end
151
+ end
152
+ @java_installed
153
+ end
154
+
155
+ def logging_config_path
156
+ return @logging_config_path if defined?(@logging_config_path)
157
+ @logging_config_path =
158
+ if log_file
159
+ logging_config = Tempfile.new('logging.properties')
160
+ logging_config.puts("handlers = java.util.logging.FileHandler")
161
+ logging_config.puts("java.util.logging.FileHandler.level = #{log_level.to_s.upcase}")
162
+ logging_config.puts("java.util.logging.FileHandler.pattern = #{log_file}")
163
+ logging_config.puts("java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter")
164
+ logging_config.flush
165
+ logging_config.close
166
+ logging_config.path
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
@@ -0,0 +1 @@
1
+ require 'sunspot/solr/server'
@@ -0,0 +1,42 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ Solr example configuration
17
+ --------------------------
18
+
19
+ To run this example configuration, use
20
+
21
+ java -jar start.jar
22
+
23
+ in this directory, and when Solr is started connect to
24
+
25
+ http://localhost:8983/solr/admin/
26
+
27
+ To add documents to the index, use the post.sh script in the exampledocs
28
+ subdirectory (while Solr is running), for example:
29
+
30
+ cd exampledocs
31
+ ./post.sh *.xml
32
+
33
+ See also README.txt in the solr subdirectory, and check
34
+ http://wiki.apache.org/solr/SolrResources for a list of tutorials and
35
+ introductory articles.
36
+
37
+ NOTE: This Solr example server references SolrCell jars outside of the server
38
+ directory with <lib> statements in the solrconfig.xml. If you make a copy of
39
+ this example server and wish to use the ExtractingRequestHandler (SolrCell),
40
+ you will need to copy the required jars into solr/lib or update the paths to
41
+ the jars in your solrconfig.xml.
42
+
@@ -0,0 +1,218 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
3
+
4
+ <!-- =============================================================== -->
5
+ <!-- Configure the Jetty Server -->
6
+ <!-- -->
7
+ <!-- Documentation of this file format can be found at: -->
8
+ <!-- http://docs.codehaus.org/display/JETTY/jetty.xml -->
9
+ <!-- -->
10
+ <!-- =============================================================== -->
11
+
12
+
13
+ <Configure id="Server" class="org.mortbay.jetty.Server">
14
+
15
+ <!-- Increase the maximum POST size to 1 MB to be able to handle large shard requests -->
16
+ <Call class="java.lang.System" name="setProperty">
17
+ <Arg>org.mortbay.jetty.Request.maxFormContentSize</Arg>
18
+ <Arg>1000000</Arg>
19
+ </Call>
20
+
21
+ <!-- =========================================================== -->
22
+ <!-- Server Thread Pool -->
23
+ <!-- =========================================================== -->
24
+ <Set name="ThreadPool">
25
+ <!-- Default bounded blocking threadpool
26
+ -->
27
+ <New class="org.mortbay.thread.BoundedThreadPool">
28
+ <Set name="minThreads">10</Set>
29
+ <Set name="lowThreads">50</Set>
30
+ <Set name="maxThreads">10000</Set>
31
+ </New>
32
+
33
+ <!-- Optional Java 5 bounded threadpool with job queue
34
+ <New class="org.mortbay.thread.concurrent.ThreadPool">
35
+ <Arg type="int">0</Arg>
36
+ <Set name="corePoolSize">10</Set>
37
+ <Set name="maximumPoolSize">250</Set>
38
+ </New>
39
+ -->
40
+ </Set>
41
+
42
+
43
+
44
+ <!-- =========================================================== -->
45
+ <!-- Set connectors -->
46
+ <!-- =========================================================== -->
47
+ <!-- One of each type! -->
48
+ <!-- =========================================================== -->
49
+
50
+ <!-- Use this connector for many frequently idle connections
51
+ and for threadless continuations.
52
+ <Call name="addConnector">
53
+ <Arg>
54
+ <New class="org.mortbay.jetty.nio.SelectChannelConnector">
55
+ <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
56
+ <Set name="maxIdleTime">30000</Set>
57
+ <Set name="Acceptors">2</Set>
58
+ <Set name="confidentialPort">8443</Set>
59
+ </New>
60
+ </Arg>
61
+ </Call>
62
+ -->
63
+
64
+ <!-- Use this connector if NIO is not available. -->
65
+ <!-- This connector is currently being used for Solr because the
66
+ nio.SelectChannelConnector showed poor performance under WindowsXP
67
+ from a single client with non-persistent connections (35s vs ~3min)
68
+ to complete 10,000 requests)
69
+ -->
70
+ <Call name="addConnector">
71
+ <Arg>
72
+ <New class="org.mortbay.jetty.bio.SocketConnector">
73
+ <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
74
+ <Set name="maxIdleTime">50000</Set>
75
+ <Set name="lowResourceMaxIdleTime">1500</Set>
76
+ <!-- Increase header buffer size from default of 4KB to 64KB to
77
+ prevent Solr from reaching this limit during large queries
78
+ -->
79
+ <Set name="headerBufferSize">65536</Set>
80
+ </New>
81
+ </Arg>
82
+ </Call>
83
+
84
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
85
+ <!-- To add a HTTPS SSL listener -->
86
+ <!-- see jetty-ssl.xml to add an ssl connector. use -->
87
+ <!-- java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml -->
88
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
89
+
90
+ <!-- =========================================================== -->
91
+ <!-- Set up global session ID manager -->
92
+ <!-- =========================================================== -->
93
+ <!--
94
+ <Set name="sessionIdManager">
95
+ <New class="org.mortbay.jetty.servlet.HashSessionIdManager">
96
+ <Set name="workerName">node1</Set>
97
+ </New>
98
+ </Set>
99
+ -->
100
+
101
+ <!-- =========================================================== -->
102
+ <!-- Set handler Collection Structure -->
103
+ <!-- =========================================================== -->
104
+ <Set name="handler">
105
+ <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
106
+ <Set name="handlers">
107
+ <Array type="org.mortbay.jetty.Handler">
108
+ <Item>
109
+ <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
110
+ </Item>
111
+ <Item>
112
+ <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
113
+ </Item>
114
+ <Item>
115
+ <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
116
+ </Item>
117
+ </Array>
118
+ </Set>
119
+ </New>
120
+ </Set>
121
+
122
+ <!-- =========================================================== -->
123
+ <!-- Configure the context deployer -->
124
+ <!-- A context deployer will deploy contexts described in -->
125
+ <!-- configuration files discovered in a directory. -->
126
+ <!-- The configuration directory can be scanned for hot -->
127
+ <!-- deployments at the configured scanInterval. -->
128
+ <!-- -->
129
+ <!-- This deployer is configured to deploy contexts configured -->
130
+ <!-- in the $JETTY_HOME/contexts directory -->
131
+ <!-- -->
132
+ <!-- =========================================================== -->
133
+ <Call name="addLifeCycle">
134
+ <Arg>
135
+ <New class="org.mortbay.jetty.deployer.ContextDeployer">
136
+ <Set name="contexts"><Ref id="Contexts"/></Set>
137
+ <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
138
+ <Set name="scanInterval">1</Set>
139
+ </New>
140
+ </Arg>
141
+ </Call>
142
+
143
+ <!-- =========================================================== -->
144
+ <!-- Configure the webapp deployer. -->
145
+ <!-- A webapp deployer will deploy standard webapps discovered -->
146
+ <!-- in a directory at startup, without the need for additional -->
147
+ <!-- configuration files. It does not support hot deploy or -->
148
+ <!-- non standard contexts (see ContextDeployer above). -->
149
+ <!-- -->
150
+ <!-- This deployer is configured to deploy webapps from the -->
151
+ <!-- $JETTY_HOME/webapps directory -->
152
+ <!-- -->
153
+ <!-- Normally only one type of deployer need be used. -->
154
+ <!-- -->
155
+ <!-- =========================================================== -->
156
+ <Call name="addLifeCycle">
157
+ <Arg>
158
+ <New class="org.mortbay.jetty.deployer.WebAppDeployer">
159
+ <Set name="contexts"><Ref id="Contexts"/></Set>
160
+ <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set>
161
+ <Set name="parentLoaderPriority">false</Set>
162
+ <Set name="extract">true</Set>
163
+ <Set name="allowDuplicates">false</Set>
164
+ <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
165
+ </New>
166
+ </Arg>
167
+ </Call>
168
+
169
+ <!-- =========================================================== -->
170
+ <!-- Configure Authentication Realms -->
171
+ <!-- Realms may be configured for the entire server here, or -->
172
+ <!-- they can be configured for a specific web app in a context -->
173
+ <!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
174
+ <!-- example). -->
175
+ <!-- =========================================================== -->
176
+ <Set name="UserRealms">
177
+ <Array type="org.mortbay.jetty.security.UserRealm">
178
+ <!--
179
+ <Item>
180
+ <New class="org.mortbay.jetty.security.HashUserRealm">
181
+ <Set name="name">Test Realm</Set>
182
+ <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
183
+ </New>
184
+ </Item>
185
+ -->
186
+ </Array>
187
+ </Set>
188
+
189
+ <!-- =========================================================== -->
190
+ <!-- Configure Request Log -->
191
+ <!-- Request logs may be configured for the entire server here, -->
192
+ <!-- or they can be configured for a specific web app in a -->
193
+ <!-- contexts configuration (see $(jetty.home)/contexts/test.xml -->
194
+ <!-- for an example). -->
195
+ <!-- =========================================================== -->
196
+ <!--
197
+ <Ref id="RequestLog">
198
+ <Set name="requestLog">
199
+ <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
200
+ <Arg><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Arg>
201
+ <Set name="retainDays">90</Set>
202
+ <Set name="append">true</Set>
203
+ <Set name="extended">false</Set>
204
+ <Set name="LogTimeZone">GMT</Set>
205
+ </New>
206
+ </Set>
207
+ </Ref>
208
+ -->
209
+
210
+ <!-- =========================================================== -->
211
+ <!-- extra options -->
212
+ <!-- =========================================================== -->
213
+ <Set name="stopAtShutdown">true</Set>
214
+ <!-- ensure/prevent Server: header being sent to browsers -->
215
+ <Set name="sendServerVersion">true</Set>
216
+
217
+ </Configure>
218
+