multi-solr 01.01.05

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +1 -0
  5. data/lib/multi_solr/base_searcher.rb +393 -0
  6. data/lib/multi_solr/filter_value_composite.rb +33 -0
  7. data/lib/multi_solr/rails_form_render_helper.rb +84 -0
  8. data/lib/multi_solr/search_request.rb +209 -0
  9. data/lib/multi_solr/search_result.rb +127 -0
  10. data/lib/multi_solr/single_core_handler.rb +341 -0
  11. data/lib/multi_solr/solr_filter_collection.rb +97 -0
  12. data/lib/multi_solr/solr_filter_date.rb +46 -0
  13. data/lib/multi_solr/solr_filter_date_range.rb +62 -0
  14. data/lib/multi_solr/solr_filter_free_query.rb +11 -0
  15. data/lib/multi_solr/solr_filter_simple.rb +96 -0
  16. data/lib/multi_solr/timeline_core_handler.rb +131 -0
  17. data/lib/multi_solr/version.rb +3 -0
  18. data/lib/multi_solr.rb +43 -0
  19. data/multi-solr.gemspec +28 -0
  20. data/spec/fixtures/solr-testdata.yml +13 -0
  21. data/spec/multi_solr/base_searcher_spec.rb +212 -0
  22. data/spec/multi_solr/search_request_spec.rb +45 -0
  23. data/spec/multi_solr/search_result_spec.rb +113 -0
  24. data/spec/multi_solr/single_core_handler_spec.rb +169 -0
  25. data/spec/multi_solr/timeline_core_handler_spec.rb +107 -0
  26. data/spec/solr_test_helper.rb +15 -0
  27. data/spec/solr_testdata_provider.rb +89 -0
  28. data/spec/spec_helper.rb +27 -0
  29. data/test-solr/.gitignore +4 -0
  30. data/test-solr/articles.xml +6 -0
  31. data/test-solr/etc/jetty.xml +227 -0
  32. data/test-solr/etc/webdefault.xml +410 -0
  33. data/test-solr/lib/jetty-6.1.26-patched-JETTY-1340.jar +0 -0
  34. data/test-solr/lib/jetty-LICENSE.txt +202 -0
  35. data/test-solr/lib/jetty-NOTICE.txt +36 -0
  36. data/test-solr/lib/jetty-util-6.1.26-patched-JETTY-1340.jar +0 -0
  37. data/test-solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
  38. data/test-solr/lib/jsp-2.1/jsp-2.1-glassfish-2.1.v20091210.jar +0 -0
  39. data/test-solr/lib/jsp-2.1/jsp-2.1-jetty-6.1.26.jar +0 -0
  40. data/test-solr/lib/jsp-2.1/jsp-api-2.1-glassfish-2.1.v20091210.jar +0 -0
  41. data/test-solr/lib/lukeall-3.4.0_1.jar +0 -0
  42. data/test-solr/lib/servlet-api-2.5-20081211.jar +0 -0
  43. data/test-solr/solr/lib/apache-solr-dataimporthandler-3.4.0.jar +0 -0
  44. data/test-solr/solr/solr.xml +20 -0
  45. data/test-solr/solr/testcore/conf/dataimport-test.xml +12 -0
  46. data/test-solr/solr/testcore/conf/schema.xml +42 -0
  47. data/test-solr/solr/testcore/conf/solr_schema.css +58 -0
  48. data/test-solr/solr/testcore/conf/solr_schema.xsl +72 -0
  49. data/test-solr/solr/testcore/conf/solrconfig.xml +72 -0
  50. data/test-solr/start-test-solr.sh +10 -0
  51. data/test-solr/start.jar +0 -0
  52. data/test-solr/webapps/solr.war +0 -0
  53. metadata +212 -0
@@ -0,0 +1,89 @@
1
+ # Helper-Klasse für das Handling von Testdaten im SOLR
2
+
3
+ require 'timeout'
4
+ require "yaml"
5
+
6
+ class SolrTestdataProvider
7
+
8
+ SOLR_TEST_INSTANCE_URL = "http://localhost:9983/solr"
9
+ SOLR_TEST_INSTANCE_START_SCRIPT = File.expand_path(File.join(File.dirname(__FILE__), '..', 'test-solr', 'start-test-solr.sh'))
10
+ TESTDATA_FILE = File.join(File.dirname(__FILE__), 'fixtures', 'solr-testdata.yml')
11
+
12
+
13
+ class << self
14
+
15
+
16
+
17
+ def load_testdata_into_solr core_name='core-01'
18
+ runtime = Benchmark.realtime do
19
+ con = solr_connection core_name
20
+
21
+ # Löschen eventuell vorhandener alter Daten
22
+ con.delete_by_query '*:*'
23
+
24
+ print "Read testdata from #{TESTDATA_FILE} ... "
25
+ docs = YAML.load_file TESTDATA_FILE
26
+ print "send data to Solr #{con.uri.to_s} ..."
27
+ con.add docs
28
+ con.commit
29
+ puts "ok."
30
+ end
31
+ puts "load solr-testdata finished in #{runtime}s"
32
+ end
33
+
34
+
35
+ # Starten der Test-Solr-Instanze falls diese noch nicht läuft
36
+ def start_test_solr_instance
37
+ unless solr_test_instance_running?
38
+ # Solr-Testinstance läuft nicht => also diese jetzt starten
39
+ start_cmd = SOLR_TEST_INSTANCE_START_SCRIPT
40
+ print "Starte Test-Solr-Instance with #{start_cmd} .."
41
+ $solr_test_instance_process = IO.popen(start_cmd)
42
+ Timeout::timeout(120) do
43
+ begin
44
+ sleep 0.5
45
+ print '.'
46
+ end while(!solr_test_instance_running?)
47
+ end
48
+ puts "ok"
49
+ end
50
+ end
51
+
52
+ def stop_test_solr_instance
53
+ if $solr_test_instance_process
54
+ print "\nStopping Test-Solr-Instance.."
55
+
56
+ # Java-Process(Jetty) als Child des gestarteten Scripts ermitteln
57
+ ps_res = `ps -o pid h --ppid #{$solr_test_instance_process.pid}`
58
+ child_pid = ps_res.to_i
59
+ Process.kill("TERM", child_pid) if child_pid > 0
60
+
61
+ $solr_test_instance_process = nil
62
+ puts "ok"
63
+ end
64
+ end
65
+
66
+
67
+ private
68
+
69
+
70
+ # Testen ob Test-Instance schon läuft
71
+ def solr_test_instance_running?
72
+ begin
73
+ con = solr_connection 'core-01'
74
+ con.head("admin/ping").response[:status] == 200
75
+ rescue => ex
76
+ #puts ex.message
77
+ return false
78
+ end
79
+ end
80
+
81
+ def solr_connection core_name=nil
82
+ url = SOLR_TEST_INSTANCE_URL
83
+ url = "#{SOLR_TEST_INSTANCE_URL}/#{core_name}" if core_name
84
+ MultiSolr.logger.debug("solr_connection: url==#{url}")
85
+ RSolr.connect :url => url
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,27 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require 'rspec'
4
+ require 'multi_solr'
5
+ require "ap"
6
+
7
+ require "solr_testdata_provider"
8
+ require "solr_test_helper"
9
+
10
+
11
+ RSpec.configure do |config|
12
+
13
+ config.mock_with :rspec
14
+
15
+
16
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
17
+ # examples within a transaction, remove the following line or assign false
18
+ # instead of true.
19
+ #config.use_transactional_fixtures = true
20
+ #config.include(RSpec::Mocks::Methods)
21
+
22
+ config.after(:suite) do
23
+ # Stoppen der Solr-Test-Instance (falls diese gestartet war)
24
+ SolrTestdataProvider.stop_test_solr_instance
25
+ end
26
+ include SolrTestHelper
27
+ end
@@ -0,0 +1,4 @@
1
+ logs
2
+ data
3
+ work
4
+ solr/*/conf/*.properties
@@ -0,0 +1,6 @@
1
+ <artikel>
2
+ <id>101</id>
3
+ <lager_id>8</lager_id>
4
+ <menge>12</menge>
5
+ <artikelnr>123456</artikelnr>
6
+ </artikel>
@@ -0,0 +1,227 @@
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
+
26
+ <New class="org.mortbay.thread.QueuedThreadPool">
27
+ <Set name="minThreads">10</Set>
28
+ <Set name="maxThreads">10000</Set>
29
+ <Set name="lowThreads">20</Set>
30
+ </New>
31
+
32
+ <!-- Optional Java 5 bounded threadpool with job queue
33
+ <New class="org.mortbay.thread.concurrent.ThreadPool">
34
+ <Set name="corePoolSize">50</Set>
35
+ <Set name="maximumPoolSize">50</Set>
36
+ </New>
37
+ -->
38
+ </Set>
39
+
40
+
41
+
42
+ <!-- =========================================================== -->
43
+ <!-- Set connectors -->
44
+ <!-- =========================================================== -->
45
+ <!-- One of each type! -->
46
+ <!-- =========================================================== -->
47
+
48
+ <!-- Use this connector for many frequently idle connections
49
+ and for threadless continuations.
50
+ -->
51
+ <!--
52
+ <Call name="addConnector">
53
+ <Arg>
54
+ <New class="org.mortbay.jetty.nio.SelectChannelConnector">
55
+ <Set name="host"><SystemProperty name="jetty.host" /></Set>
56
+ <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
57
+ <Set name="maxIdleTime">30000</Set>
58
+ <Set name="Acceptors">2</Set>
59
+ <Set name="statsOn">false</Set>
60
+ <Set name="confidentialPort">8443</Set>
61
+ <Set name="lowResourcesConnections">5000</Set>
62
+ <Set name="lowResourcesMaxIdleTime">5000</Set>
63
+ </New>
64
+ </Arg>
65
+ </Call>
66
+ -->
67
+
68
+ <!-- This connector is currently being used for Solr because it
69
+ showed better performance than nio.SelectChannelConnector
70
+ for typical Solr requests. -->
71
+ <Call name="addConnector">
72
+ <Arg>
73
+ <New class="org.mortbay.jetty.bio.SocketConnector">
74
+ <Set name="host"><SystemProperty name="jetty.host" /></Set>
75
+ <Set name="port"><SystemProperty name="jetty.port" default="8983"/></Set>
76
+ <Set name="maxIdleTime">50000</Set>
77
+ <Set name="lowResourceMaxIdleTime">1500</Set>
78
+ <Set name="statsOn">false</Set>
79
+ </New>
80
+ </Arg>
81
+ </Call>
82
+
83
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
84
+ <!-- To add a HTTPS SSL listener -->
85
+ <!-- see jetty-ssl.xml to add an ssl connector. use -->
86
+ <!-- java -jar start.jar etc/jetty.xml etc/jetty-ssl.xml -->
87
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
88
+
89
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
90
+ <!-- To allow Jetty to be started from xinetd -->
91
+ <!-- mixin jetty-xinetd.xml: -->
92
+ <!-- java -jar start.jar etc/jetty.xml etc/jetty-xinetd.xml -->
93
+ <!-- -->
94
+ <!-- See jetty-xinetd.xml for further instructions. -->
95
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
96
+
97
+ <!-- =========================================================== -->
98
+ <!-- Set up global session ID manager -->
99
+ <!-- =========================================================== -->
100
+ <!--
101
+ <Set name="sessionIdManager">
102
+ <New class="org.mortbay.jetty.servlet.HashSessionIdManager">
103
+ <Set name="workerName">node1</Set>
104
+ </New>
105
+ </Set>
106
+ -->
107
+
108
+ <!-- =========================================================== -->
109
+ <!-- Set handler Collection Structure -->
110
+ <!-- =========================================================== -->
111
+ <Set name="handler">
112
+ <New id="Handlers" class="org.mortbay.jetty.handler.HandlerCollection">
113
+ <Set name="handlers">
114
+ <Array type="org.mortbay.jetty.Handler">
115
+ <Item>
116
+ <New id="Contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"/>
117
+ </Item>
118
+ <Item>
119
+ <New id="DefaultHandler" class="org.mortbay.jetty.handler.DefaultHandler"/>
120
+ </Item>
121
+ <Item>
122
+ <New id="RequestLog" class="org.mortbay.jetty.handler.RequestLogHandler"/>
123
+ </Item>
124
+ </Array>
125
+ </Set>
126
+ </New>
127
+ </Set>
128
+
129
+ <!-- =========================================================== -->
130
+ <!-- Configure the context deployer -->
131
+ <!-- A context deployer will deploy contexts described in -->
132
+ <!-- configuration files discovered in a directory. -->
133
+ <!-- The configuration directory can be scanned for hot -->
134
+ <!-- deployments at the configured scanInterval. -->
135
+ <!-- -->
136
+ <!-- This deployer is configured to deploy contexts configured -->
137
+ <!-- in the $JETTY_HOME/contexts directory -->
138
+ <!-- -->
139
+ <!-- =========================================================== -->
140
+ <Call name="addLifeCycle">
141
+ <Arg>
142
+ <New class="org.mortbay.jetty.deployer.ContextDeployer">
143
+ <Set name="contexts"><Ref id="Contexts"/></Set>
144
+ <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts</Set>
145
+ <Set name="scanInterval">5</Set>
146
+ </New>
147
+ </Arg>
148
+ </Call>
149
+
150
+ <!-- =========================================================== -->
151
+ <!-- Configure the webapp deployer. -->
152
+ <!-- A webapp deployer will deploy standard webapps discovered -->
153
+ <!-- in a directory at startup, without the need for additional -->
154
+ <!-- configuration files. It does not support hot deploy or -->
155
+ <!-- non standard contexts (see ContextDeployer above). -->
156
+ <!-- -->
157
+ <!-- This deployer is configured to deploy webapps from the -->
158
+ <!-- $JETTY_HOME/webapps directory -->
159
+ <!-- -->
160
+ <!-- Normally only one type of deployer need be used. -->
161
+ <!-- -->
162
+ <!-- =========================================================== -->
163
+ <Call name="addLifeCycle">
164
+ <Arg>
165
+ <New class="org.mortbay.jetty.deployer.WebAppDeployer">
166
+ <Set name="contexts"><Ref id="Contexts"/></Set>
167
+ <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set>
168
+ <Set name="parentLoaderPriority">false</Set>
169
+ <Set name="extract">true</Set>
170
+ <Set name="allowDuplicates">false</Set>
171
+ <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
172
+ </New>
173
+ </Arg>
174
+ </Call>
175
+
176
+ <!-- =========================================================== -->
177
+ <!-- Configure Authentication Realms -->
178
+ <!-- Realms may be configured for the entire server here, or -->
179
+ <!-- they can be configured for a specific web app in a context -->
180
+ <!-- configuration (see $(jetty.home)/contexts/test.xml for an -->
181
+ <!-- example). -->
182
+ <!-- =========================================================== -->
183
+ <!--
184
+ <Set name="UserRealms">
185
+ <Array type="org.mortbay.jetty.security.UserRealm">
186
+ <Item>
187
+ <New class="org.mortbay.jetty.security.HashUserRealm">
188
+ <Set name="name">Test Realm</Set>
189
+ <Set name="config"><SystemProperty name="jetty.home" default="."/>/etc/realm.properties</Set>
190
+ <Set name="refreshInterval">0</Set>
191
+ </New>
192
+ </Item>
193
+ </Array>
194
+ </Set>
195
+ -->
196
+
197
+ <!-- =========================================================== -->
198
+ <!-- Configure Request Log -->
199
+ <!-- Request logs may be configured for the entire server here, -->
200
+ <!-- or they can be configured for a specific web app in a -->
201
+ <!-- contexts configuration (see $(jetty.home)/contexts/test.xml -->
202
+ <!-- for an example). -->
203
+ <!-- =========================================================== -->
204
+ <!--
205
+ <Ref id="RequestLog">
206
+ <Set name="requestLog">
207
+ <New id="RequestLogImpl" class="org.mortbay.jetty.NCSARequestLog">
208
+ <Set name="filename"><SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log</Set>
209
+ <Set name="filenameDateFormat">yyyy_MM_dd</Set>
210
+ <Set name="retainDays">90</Set>
211
+ <Set name="append">true</Set>
212
+ <Set name="extended">false</Set>
213
+ <Set name="logCookies">false</Set>
214
+ <Set name="LogTimeZone">GMT</Set>
215
+ </New>
216
+ </Set>
217
+ </Ref>
218
+ -->
219
+ <!-- =========================================================== -->
220
+ <!-- extra options -->
221
+ <!-- =========================================================== -->
222
+ <Set name="stopAtShutdown">true</Set>
223
+ <Set name="sendServerVersion">false</Set>
224
+ <Set name="sendDateHeader">false</Set>
225
+ <Set name="gracefulShutdown">1000</Set>
226
+
227
+ </Configure>