rsolr 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt ADDED
@@ -0,0 +1,228 @@
1
+ 0.9.6 - September 9, 2009
2
+ Added ability to create direct connections from existing Java::OrgApacheSolrCore::SolrCore
3
+ Added ability to send queries using POST
4
+ - solr.request '/select', :q=>'*:*', :method=>:post
5
+
6
+ 0.9.5 - September 4, 2009
7
+ Removed Array #extract_options!
8
+ Removed the Connection #send_request method (now #request)
9
+ Removed the Connection #select method -- still works, but this now ends up calling Connection #method_missing
10
+ Removed HTTPClient::Connector
11
+ - HTTPClient now uses a method called #connect (like RSolr.connect)
12
+ - This method accepts 1 or 2 args, see the #connect method comments
13
+ Changed the way the HTTP client adapter is set. Now just pass in when connecting:
14
+ - RSolr.connect(:http, :adapter=>curb, :url=>'http://solr.com')
15
+ Moved Message::Builders to Message::Adapter
16
+ Made Connection a module and moved class methods to "Base" class
17
+ Made HTTPClient a module and moved class methods to "Base" class
18
+ Removed the "adapter.rb" files -- Adapter modules are defined in the parent module file.
19
+ Moved Message module/singleton functionality to Message::Builder class
20
+ XML message adapter API change: no longer a singleton, must instantiate Message::Builder
21
+ Made RSolr::Connection #message public -- can change the adapter as needed; connection.message.adapter = RSolr::Message::Adapter::LibXML.new
22
+ More tests for HTTPClient::Util
23
+ Simplified url/query building in HTTPClient::Util
24
+ Updated tests accordingly
25
+
26
+ 0.9.1 - July 22, 2009
27
+ Added LibXml builder support (Thanks to Mat Brown - github.com/outoftime)
28
+
29
+ 0.9.0 - July 17, 2009
30
+ Added ability to use DirectSolrConnection instance when connecting
31
+ Loading Java classes using full package name
32
+
33
+ 0.8.9 - June 30, 2009
34
+ Deprecated hash syntax fix from outoftime/rsolr (Mat Brown)
35
+
36
+ 0.8.8 - May 6, 2009
37
+ Added method :request to RSolr::Connection
38
+ - this method is an alias for send_request
39
+
40
+ 0.8.7 - May 6, 2009
41
+ Added method_missing to RSolr::Connection, which sets the request handler path,
42
+ based on the method name:
43
+ # this sends a request like: /music_library?q=>coltrane
44
+ solr.music_library :q=>'coltrane'
45
+ Removed the core_ext file, put the Array extension code directly into rsolr.rb
46
+
47
+ 0.8.6 - April 25, 2009
48
+ Removed the Mash stuff -- which means the response keys from solr are only accessable using String based keys.
49
+ Use RSolr::Ext if you want more magic.
50
+
51
+ 0.8.5 - April 7, 2009
52
+ The RSolr::Message #add method now accepts a single Message::Document or an array of Message::Document objects
53
+ The Message::Document class has a new method: #add_field
54
+ Tests added for both changes
55
+ Permissions of files changed to non-executable
56
+ -- the above changes were made by Mat Brown, thank you Mat!
57
+ Added CannedSolrResponse module for mocks in the specs... not used yet
58
+
59
+ 0.8.4 - April 3, 2009
60
+ New test suite using RSpec and mocks coming. Run "rake spec"
61
+ - added specs for RSolr and RSolr::Connection
62
+
63
+ 0.8.3 - April 3, 2009
64
+ RSolr::Connection
65
+ - removed the block functionality of send_request and related methods
66
+ - this was used to gain access to the raw adapter response
67
+ - added #adapter_response method to all response objects
68
+ - this is used to get access to the original adapter response:
69
+ response = rsolr.select(:q=>'test')
70
+ response.adapter_response[:status_code]
71
+
72
+ 0.8.2 - March 24, 2009
73
+ Changed RSolr.connect method to accept one options hash argument
74
+ - This hash gets passed to the Connection object and the adapter
75
+ Updated tests, examples and README.rdoc to reflect this change
76
+ Bumped the version up in gemspec and the RSolr module
77
+
78
+ 0.8.1 - March 12, 2009
79
+ Added RSolr.escape and RSolr::Connection.new.escape
80
+ - tests in rsolr_test
81
+ Added ability to set doc and field attributes when adding documents via Message.add
82
+
83
+ 0.8.0 - March 6, 2009
84
+ Removed all response wrapper classes (now returning a simple hash for ruby responses)
85
+ Removed RSolr::Query - this library needs an external partner lib, RSolrExt etc..
86
+ changed query method to select
87
+ added send_request method to Connection for custom requests:
88
+ send_request '/my-handler', {:start=>0}, post_data=nil
89
+ moved Connection::Base to Connection
90
+ moved Connection::Adapter::* to Adapter::*
91
+
92
+ 0.7.1 - February 27, 2009
93
+ Added simple query helper module -> RSolr::Query
94
+ Added tests for RSolr::Query
95
+ Modified Test::Unit::TestCase in test/test_helpers.rb
96
+
97
+ 0.7.0 - February 20, 2009
98
+ Removed all param mapping behavior, code and tests
99
+ - this stuff just gunks up rsolr and should be in an extension of some sort
100
+ Can now specify the request handler in all RSolr::Connection::Base methods as the first argument:
101
+ - solr.query 'select', :q=>'ipod'
102
+ - solr.query 'catalog', :q=>'humphry'
103
+ - solr.query :q=>'big' # defaults to the /select handler
104
+
105
+ 0.6.9 - January 29, 2009
106
+ Simplified facet response methods
107
+ Main facet method is called #facets
108
+ - returns an array of Response::Facet instances
109
+ - each Facet instance has field and values attributes
110
+ -- the values attribute is an array with FacetValue instances which have @value and @hits
111
+ Added ability to set Connection::Base @param_adapters using :dismax or :standard
112
+ instead of full class constant
113
+ updated comments for #search method
114
+ Updated tests
115
+ Bumped up version
116
+
117
+ 0.6.8 - January 28, 2009
118
+ New method added to RSolr::Connection::Base - #find_values_for_facet
119
+ This method searches for facet values only, and sets the :rows param to 0
120
+ - returns an RSolr::Response::Query::Base instance
121
+ Example:
122
+ search_params[:facets][:offset]=0
123
+ search_params[:facets][:limit]=5
124
+ response = solr.search_facet_by_name(:language_facet, search_params)
125
+
126
+ 0.6.7 - January 27, 2009
127
+ The Symbol extension in core_ext.rb was cause for some REALLY painful debuging - so I removed it :(
128
+ This means no more :q.alt or :facet.field until RSolr gets a really nice query-builder module happening.
129
+
130
+ 0.6.6 - January 26, 2009
131
+ Added #get method helper to RSolr::Response::Query::DocExt
132
+ # doc.get(key, opts)
133
+ # key is the name of the field
134
+ # opts is a hash with the following valid keys:
135
+ # - :sep - a string used for joining multivalued field values
136
+ # - :default - a value to return when the key doesn't exist
137
+ # if :sep is nil and the field is a multivalued field, the array is returned
138
+
139
+ 0.6.5 - January 26, 2009
140
+ Removed to_mash everywhere, except for usage in RSolr::Response
141
+ Added a #close method to the Direct adapter
142
+ - this closes the connection and sets the @connection variable to nil
143
+ Removed to_mash in RSolr::Connection::Base
144
+ Changed RSolr::Response::Query::Doc to DocExt
145
+ - this no longer extends Mash
146
+ - each doc in the response now uses the #extend method to mixin the new DocExt module
147
+ Added #teardown method in direct connection test, this method closes the connection
148
+ Updated the connection test methods a bit
149
+
150
+ 0.6.4 - January 26, 2009
151
+ Updated the mapping output for the :filters and :phrase_filters (when using the #search method)
152
+ - now sending multiple fq's instead of one
153
+ Updated mapping tests
154
+
155
+ 0.6.3 - January 21, 2009
156
+ Added a new param mapping module: RSolr::Connection::ParamMapping
157
+ Mapping only for fields that need conversion/escaping or nested (facet.*) etc.
158
+ This new module can be activated by using the #search method
159
+ New tests for ParamMapping
160
+
161
+ 0.6.2 - January 14, 2009
162
+ Removed mapping and indexer modules -- seems to me that a general purpose mapping library
163
+ would be more valuable than an embedded module in RSolr ( RMapper ?)
164
+ This helps lighten RSolr a bit too
165
+
166
+ 0.6.1 - January 13, 2009
167
+ Removed SearchExt and mapping until this library gets some real use
168
+ The only param mapping now is for :page and :per_page via the #search method
169
+ The Connection::Base #query method does NO mapping now
170
+
171
+ 0.6.0 - January 9, 2009
172
+ Removed first argument from RSolr.connect, the "adapter_name"
173
+ The adapter is now set using the :adapter key when passing in options to RSolr.connect:
174
+ s = RSolr.connect(:adapter=>:direct)
175
+
176
+ 0.5.9 - January 7, 2009
177
+ Finally brought in the ExtLib Mash classes for incoming params and response hashes from solr
178
+ - this gives the ability to access/set values for hashes using strings OR symbols (HashWithIndifferentAccess)
179
+ Organized response tests
180
+ Added more response tests
181
+ Simplified the RSolr::Response::Base class by supporting only raw/string ruby input
182
+ Added method to Response::IndexInfo for grabbing a Solr field list
183
+
184
+ 0.5.7 - January 5, 2009
185
+ Changed name from Solr to RSolr, changed all references to Solr to RSolr
186
+ Added new tests for RSolr::Mapper and RSolr::Message
187
+
188
+ 0.5.6 - December 30, 2008
189
+ solr.gemspec cleanedup thanks to shairontoledo on github! :)
190
+ Added Solr::Response::Query::Facet module with helpers from the delsolr project
191
+ Also added test stub in test/connection/search_ext_test_methods.rb
192
+ Fixed pagination math errors
193
+ Added new SearchExt helper field: :phrase_filters
194
+ This will add quoted values to the :filters (fq solr param) hash for doing easier facet requests
195
+
196
+ Be sure to check out the new demo app: http://github.com/mwmitchell/consuminator/tree/master
197
+
198
+ 0.5.5 - December 29, 2008
199
+ Fixed bug where accessing a field by method name failed:
200
+ docs.each do |doc|
201
+ doc.timestamp
202
+ end
203
+ Fixed bug where using the #has? method on a doc failed:
204
+ docs.each do |doc|
205
+ doc.has?('timestamp')
206
+ end
207
+ Removed invalid autoload in Solr module
208
+ Fixed spelling error in Solr::Connection::SearchExt (thanks to matthewrudy)
209
+
210
+ 0.5.4 - December 29, 2008
211
+ Re-organized the main Solr adapters, they're now in Solr::Connection::Adapter instead of Solr::Adapter
212
+ All responses from HTTPClient and Connection::Adapter::Direct return a hash with the following keys:
213
+ :status_code
214
+ :body
215
+ :params
216
+ :url
217
+ :path
218
+ :headers
219
+ :data
220
+ This hash is now available in the solr response objects as #source - this will be useful in testing and debugging by allowing you to see the generated params and queries... example:
221
+ response = Solr.query(:q=>'*:*')
222
+ response.source[:params]
223
+ response.source[:body]
224
+ response.source[:url]
225
+ Added MultiValue field support in Solr::Message, thanks to Fouad Mardini
226
+ Bug in Solr::Connection::SearchExt where the :q params was not getting generated - fixed by Fouad Mardini
227
+ Organized tests a bit, moved connection tests into test/connection
228
+ Fixed a bug in Solr::Connection::Adapter::HTTP where invalid HTTP POST headers were being generated
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2008-2009 Matt Mitchell
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.rdoc ADDED
@@ -0,0 +1,148 @@
1
+ =RSolr
2
+
3
+ A Ruby client for Apache Solr. RSolr has been developed to be simple and extendable. It features transparent JRuby DirectSolrConnection support and a simple Hash-in, Hash-out architecture.
4
+
5
+ == Installation:
6
+ gem sources -a http://gems.github.com
7
+ sudo gem install mwmitchell-rsolr
8
+
9
+ ==Related Resources & Projects
10
+ * {Solr}[http://lucene.apache.org/solr/]
11
+ * {RSolr Google Group}[http://groups.google.com/group/rsolr]
12
+ * {RSolr::Ext}[http://github.com/mwmitchell/rsolr-ext] -- an extension kit for RSolr
13
+ * {Sunspot}[http://github.com/outoftime/sunspot] -- an awesome Solr DSL, built with RSolr
14
+ * {Blacklight}[http://blacklightopac.org] -- a next generation Library OPAC, built with RSolr
15
+ * {solr-ruby}[http://wiki.apache.org/solr/solr-ruby] -- the original Solr Ruby Gem
16
+
17
+ == Simple usage:
18
+ require 'rubygems'
19
+ require 'rsolr'
20
+ solr = RSolr.connect :url=>'http://solrserver.com'
21
+
22
+ # send a request to /select
23
+ response = rsolr.select :q=>'*:*'
24
+
25
+ # send a request to a custom request handler; /catalog
26
+ response = rsolr.request '/catalog', :q=>'*:*'
27
+
28
+ # alternative to above:
29
+ response = rsolr.catalog :q=>'*:*'
30
+
31
+ To use a DirectSolrConnection (no http) in JRuby:
32
+
33
+ solr = RSolr.connect(:direct,
34
+ :home_dir=>'/path/to/solr/home',
35
+ :dist_dir=>'/path/to/solr/distribution'
36
+ )
37
+
38
+ For more information about DirecSolrConnection, see the {API}[http://lucene.apache.org/solr/api/org/apache/solr/servlet/DirectSolrConnection.html].
39
+
40
+
41
+ == Querying
42
+ Use the #select method to send requests to the /select handler:
43
+ response = solr.select({
44
+ :q=>'washington',
45
+ :start=>0,
46
+ :rows=>10
47
+ })
48
+
49
+ The params sent into the method are sent to Solr as-is. The one exception is if a value is an array. When an array is used, multiple parameters are generated for the Solr query. Example:
50
+
51
+ solr.select :q=>'roses', :fq=>['red', 'violet']
52
+
53
+ The above statement generates this Solr query:
54
+
55
+ ?q=roses&fq=red&fq=violet
56
+
57
+ Use the #request method for a custom request handler path:
58
+ response = solr.request '/documents', :q=>'test'
59
+
60
+ A shortcut for the above example:
61
+ response = solr.documents :q=>'test'
62
+
63
+
64
+ == Updating Solr
65
+ Updating can be done using native Ruby structures. Hashes are used for single documents and arrays are used for a collection of documents (hashes). These structures get turned into simple XML "messages". Raw XML strings can also be used.
66
+
67
+ Raw XML via #update
68
+ solr.update '</commit>'
69
+ solr.update '</optimize>'
70
+
71
+ Single document via #add
72
+ solr.add :id=>1, :price=>1.00
73
+
74
+ Multiple documents via #add
75
+ documents = [{:id=>1, :price=>1.00}, {:id=>2, :price=>10.50}]
76
+ solr.add documents
77
+
78
+ When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements (docs and fields) when using the #add method:
79
+
80
+ doc = {:id=>1, :price=>1.00}
81
+ add_attributes = {:allowDups=>false, :commitWithin=>10.0}
82
+ solr.add(doc, add_attributes) do |doc|
83
+ # boost each document
84
+ doc.attrs[:boost] = 1.5
85
+ # boost the price field:
86
+ doc.field_by_name(:price).attrs[:boost] = 2.0
87
+ end
88
+
89
+ Delete by id
90
+ solr.delete_by_id 1
91
+ or an array of ids
92
+ solr.delete_by_id [1, 2, 3, 4]
93
+
94
+ Delete by query:
95
+ solr.delete_by_query 'price:1.00'
96
+ Delete by array of queries
97
+ solr.delete_by_query ['price:1.00', 'price:10.00']
98
+
99
+ Commit & optimize shortcuts
100
+ solr.commit
101
+ solr.optimize
102
+
103
+ ===XML Builders for RSolr
104
+ As of version 0.9.1, RSolr can use LibXml to create the update messages sent to solr. To switch from Builder to LibXml, set the RSolr::Message.builder like:
105
+ solr = RSolr.connect
106
+ solr.message.adapter = RSolr::Message::Adapter::Libxml.new
107
+
108
+
109
+ == Response Formats
110
+ The default response format is Ruby. When the :wt param is set to :ruby, the response is eval'd resulting in a Hash. You can get a raw response by setting the :wt to "ruby" - notice, the string -- not a symbol. RSolr will eval the Ruby string ONLY if the :wt value is :ruby. All other response formats are available as expected, :wt=>'xml' etc..
111
+
112
+ ===Evaluated Ruby (default)
113
+ solr.select(:wt=>:ruby) # notice :ruby is a Symbol
114
+ ===Raw Ruby
115
+ solr.select(:wt=>'ruby') # notice 'ruby' is a String
116
+
117
+ ===XML:
118
+ solr.select(:wt=>:xml)
119
+ ===JSON:
120
+ solr.select(:wt=>:json)
121
+
122
+ You can access the original request context (path, params, url etc.) by calling the #adapter_response method:
123
+ response = solr.select :q=>'*:*'
124
+ response.adapter_response[:status_code]
125
+ response.adapter_response[:body]
126
+ response.adapter_response[:url]
127
+
128
+ The adapter_response is a hash that contains the generated params, url, path, post data, headers etc., very useful for debugging and testing.
129
+
130
+
131
+ == HTTP Client Adapter
132
+ You can specify the http client adapter:
133
+ :net_http uses the standard Net::HTTP library
134
+ :curb uses the C based "curl" library
135
+
136
+ NOTE: The Net::Http is the default adapter.
137
+
138
+ Example:
139
+
140
+ RSolr.connect(:adapter => :curb)
141
+ RSolr.connect(:adapter => :net_http)
142
+
143
+ Intereseting read about Ruby's Net::HTTP library:
144
+ http://apocryph.org/2008/11/09/more_indepth_analysis_ruby_http_client_performance
145
+
146
+ NOTE: You can't use the :curb adapter under jRuby. To install curb:
147
+
148
+ sudo gem install curb
data/Rakefile ADDED
@@ -0,0 +1,76 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ namespace :rsolr do
6
+
7
+ desc "Starts the HTTP server used for running HTTP connection tests"
8
+ task :start_test_server do
9
+ system "cd apache-solr/example; java -jar start.jar"
10
+ end
11
+
12
+ end
13
+
14
+ task :default => [:test_units]
15
+
16
+ # rake package
17
+
18
+ require 'rubygems'
19
+ require 'rake/gempackagetask'
20
+ raw_spec = File.read 'rsolr.gemspec'
21
+ spec = eval(raw_spec)
22
+ Rake::GemPackageTask.new(spec) do |pkg|
23
+ pkg.need_tar = true
24
+ end
25
+
26
+ desc "Run basic tests"
27
+ Rake::TestTask.new("test_units") { |t|
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = true
30
+ t.warning = true
31
+ t.libs << "test"
32
+ }
33
+
34
+ require 'spec/rake/spectask'
35
+
36
+ desc "Run specs"
37
+ Spec::Rake::SpecTask.new('spec') do |t|
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ t.libs += ["lib", "spec"]
40
+ end
41
+
42
+ desc 'Run specs' # this task runs each test in its own process
43
+ task :specs do
44
+ require 'rubygems'
45
+ require 'facets/more/filelist' unless defined?(FileList)
46
+ files = FileList["**/*_spec.rb"]
47
+ p files.to_a
48
+ files.each do |filename|
49
+ system "cd #{File.dirname(filename)} && ruby #{File.basename(filename)}"
50
+ end
51
+ end
52
+
53
+ desc "Run specs"
54
+ Rake::TestTask.new("specs") { |t|
55
+ t.pattern = 'spec/**/*_spec.rb'
56
+ t.verbose = true
57
+ t.warning = true
58
+ t.libs += ["lib", "spec"]
59
+ }
60
+
61
+ # Clean house
62
+ desc 'Clean up tmp files.'
63
+ task :clean do |t|
64
+ FileUtils.rm_rf "doc"
65
+ FileUtils.rm_rf "pkg"
66
+ end
67
+
68
+ # Rdoc
69
+ desc 'Generate documentation for the rsolr gem.'
70
+ Rake::RDocTask.new(:doc) do |rdoc|
71
+ rdoc.rdoc_dir = 'doc'
72
+ rdoc.title = 'RSolr'
73
+ rdoc.options << '--line-numbers' << '--inline-source'
74
+ rdoc.rdoc_files.include('README.rdoc')
75
+ rdoc.rdoc_files.include('lib/**/*.rb')
76
+ end