mdwan-rsolr 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES.txt ADDED
@@ -0,0 +1,157 @@
1
+ 0.8.2 - March 24, 2009
2
+ Changed RSolr.connect method to accept one options hash argument
3
+ - This hash gets passed to the Connection object and the adapter
4
+ Updated tests, examples and README.rdoc to reflect this change
5
+ Bumped the version up in gemspec and the RSolr module
6
+
7
+ 0.8.1 - March 12, 2009
8
+ Added RSolr.escape and RSolr::Connection.new.escape
9
+ - tests in rsolr_test
10
+ Added ability to set doc and field attributes when adding documents via Message.add
11
+
12
+ 0.8.0 - March 6, 2009
13
+ Removed all response wrapper classes (now returning a simple hash for ruby responses)
14
+ Removed RSolr::Query - this library needs an external partner lib, RSolrExt etc..
15
+ changed query method to select
16
+ added send_request method to Connection for custom requests:
17
+ send_request '/my-handler', {:start=>0}, post_data=nil
18
+ moved Connection::Base to Connection
19
+ moved Connection::Adapter::* to Adapter::*
20
+
21
+ 0.7.1 - February 27, 2009
22
+ Added simple query helper module -> RSolr::Query
23
+ Added tests for RSolr::Query
24
+ Modified Test::Unit::TestCase in test/test_helpers.rb
25
+
26
+ 0.7.0 - February 20, 2009
27
+ Removed all param mapping behavior, code and tests
28
+ - this stuff just gunks up rsolr and should be in an extension of some sort
29
+ Can now specify the request handler in all RSolr::Connection::Base methods as the first argument:
30
+ - solr.query 'select', :q=>'ipod'
31
+ - solr.query 'catalog', :q=>'humphry'
32
+ - solr.query :q=>'big' # defaults to the /select handler
33
+
34
+ 0.6.9 - January 29, 2009
35
+ Simplified facet response methods
36
+ Main facet method is called #facets
37
+ - returns an array of Response::Facet instances
38
+ - each Facet instance has field and values attributes
39
+ -- the values attribute is an array with FacetValue instances which have @value and @hits
40
+ Added ability to set Connection::Base @param_adapters using :dismax or :standard
41
+ instead of full class constant
42
+ updated comments for #search method
43
+ Updated tests
44
+ Bumped up version
45
+
46
+ 0.6.8 - January 28, 2009
47
+ New method added to RSolr::Connection::Base - #find_values_for_facet
48
+ This method searches for facet values only, and sets the :rows param to 0
49
+ - returns an RSolr::Response::Query::Base instance
50
+ Example:
51
+ search_params[:facets][:offset]=0
52
+ search_params[:facets][:limit]=5
53
+ response = solr.search_facet_by_name(:language_facet, search_params)
54
+
55
+ 0.6.7 - January 27, 2009
56
+ The Symbol extension in core_ext.rb was cause for some REALLY painful debuging - so I removed it :(
57
+ This means no more :q.alt or :facet.field until RSolr gets a really nice query-builder module happening.
58
+
59
+ 0.6.6 - January 26, 2009
60
+ Added #get method helper to RSolr::Response::Query::DocExt
61
+ # doc.get(key, opts)
62
+ # key is the name of the field
63
+ # opts is a hash with the following valid keys:
64
+ # - :sep - a string used for joining multivalued field values
65
+ # - :default - a value to return when the key doesn't exist
66
+ # if :sep is nil and the field is a multivalued field, the array is returned
67
+
68
+ 0.6.5 - January 26, 2009
69
+ Removed to_mash everywhere, except for usage in RSolr::Response
70
+ Added a #close method to the Direct adapter
71
+ - this closes the connection and sets the @connection variable to nil
72
+ Removed to_mash in RSolr::Connection::Base
73
+ Changed RSolr::Response::Query::Doc to DocExt
74
+ - this no longer extends Mash
75
+ - each doc in the response now uses the #extend method to mixin the new DocExt module
76
+ Added #teardown method in direct connection test, this method closes the connection
77
+ Updated the connection test methods a bit
78
+
79
+ 0.6.4 - January 26, 2009
80
+ Updated the mapping output for the :filters and :phrase_filters (when using the #search method)
81
+ - now sending multiple fq's instead of one
82
+ Updated mapping tests
83
+
84
+ 0.6.3 - January 21, 2009
85
+ Added a new param mapping module: RSolr::Connection::ParamMapping
86
+ Mapping only for fields that need conversion/escaping or nested (facet.*) etc.
87
+ This new module can be activated by using the #search method
88
+ New tests for ParamMapping
89
+
90
+ 0.6.2 - January 14, 2009
91
+ Removed mapping and indexer modules -- seems to me that a general purpose mapping library
92
+ would be more valuable than an embedded module in RSolr ( RMapper ?)
93
+ This helps lighten RSolr a bit too
94
+
95
+ 0.6.1 - January 13, 2009
96
+ Removed SearchExt and mapping until this library gets some real use
97
+ The only param mapping now is for :page and :per_page via the #search method
98
+ The Connection::Base #query method does NO mapping now
99
+
100
+ 0.6.0 - January 9, 2009
101
+ Removed first argument from RSolr.connect, the "adapter_name"
102
+ The adapter is now set using the :adapter key when passing in options to RSolr.connect:
103
+ s = RSolr.connect(:adapter=>:direct)
104
+
105
+ 0.5.9 - January 7, 2009
106
+ Finally brought in the ExtLib Mash classes for incoming params and response hashes from solr
107
+ - this gives the ability to access/set values for hashes using strings OR symbols (HashWithIndifferentAccess)
108
+ Organized response tests
109
+ Added more response tests
110
+ Simplified the RSolr::Response::Base class by supporting only raw/string ruby input
111
+ Added method to Response::IndexInfo for grabbing a Solr field list
112
+
113
+ 0.5.7 - January 5, 2009
114
+ Changed name from Solr to RSolr, changed all references to Solr to RSolr
115
+ Added new tests for RSolr::Mapper and RSolr::Message
116
+
117
+ 0.5.6 - December 30, 2008
118
+ solr.gemspec cleanedup thanks to shairontoledo on github! :)
119
+ Added Solr::Response::Query::Facet module with helpers from the delsolr project
120
+ Also added test stub in test/connection/search_ext_test_methods.rb
121
+ Fixed pagination math errors
122
+ Added new SearchExt helper field: :phrase_filters
123
+ This will add quoted values to the :filters (fq solr param) hash for doing easier facet requests
124
+
125
+ Be sure to check out the new demo app: http://github.com/mwmitchell/consuminator/tree/master
126
+
127
+ 0.5.5 - December 29, 2008
128
+ Fixed bug where accessing a field by method name failed:
129
+ docs.each do |doc|
130
+ doc.timestamp
131
+ end
132
+ Fixed bug where using the #has? method on a doc failed:
133
+ docs.each do |doc|
134
+ doc.has?('timestamp')
135
+ end
136
+ Removed invalid autoload in Solr module
137
+ Fixed spelling error in Solr::Connection::SearchExt (thanks to matthewrudy)
138
+
139
+ 0.5.4 - December 29, 2008
140
+ Re-organized the main Solr adapters, they're now in Solr::Connection::Adapter instead of Solr::Adapter
141
+ All responses from HTTPClient and Connection::Adapter::Direct return a hash with the following keys:
142
+ :status_code
143
+ :body
144
+ :params
145
+ :url
146
+ :path
147
+ :headers
148
+ :data
149
+ 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:
150
+ response = Solr.query(:q=>'*:*')
151
+ response.source[:params]
152
+ response.source[:body]
153
+ response.source[:url]
154
+ Added MultiValue field support in Solr::Message, thanks to Fouad Mardini
155
+ Bug in Solr::Connection::SearchExt where the :q params was not getting generated - fixed by Fouad Mardini
156
+ Organized tests a bit, moved connection tests into test/connection
157
+ Fixed a bug in Solr::Connection::Adapter::HTTP where invalid HTTP POST headers were being generated
data/LICENSE ADDED
@@ -0,0 +1,67 @@
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.
14
+
15
+ ========================================================================
16
+
17
+ For use of the lib/Mash/extlib code:
18
+
19
+ ========================================================================
20
+
21
+ Copyright (c) 2008 Sam Smoot.
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ "Software"), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
+
42
+ ---
43
+ ---
44
+
45
+ Some portions of blank.rb and mash.rb are verbatim copies of software
46
+ licensed under the MIT license. That license is included below:
47
+
48
+ Copyright (c) 2005-2008 David Heinemeier Hansson
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining
51
+ a copy of this software and associated documentation files (the
52
+ "Software"), to deal in the Software without restriction, including
53
+ without limitation the rights to use, copy, modify, merge, publish,
54
+ distribute, sublicense, and/or sell copies of the Software, and to
55
+ permit persons to whom the Software is furnished to do so, subject to
56
+ the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be
59
+ included in all copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
62
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
64
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
65
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
66
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
67
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,126 @@
1
+ =RSolr
2
+
3
+ A Ruby client for Apache Solr. Has transparent JRuby support by using "org.apache.solr.servlet.DirectSolrConnection" as a connection adapter.
4
+
5
+ ==Installation:
6
+ gem sources -a http://gems.github.com
7
+ sudo gem install mwmitchell-rsolr
8
+
9
+ ==Community
10
+ http://groups.google.com/group/rsolr
11
+
12
+ ==Simple usage:
13
+ require 'rubygems'
14
+ require 'rsolr'
15
+ rsolr = RSolr.connect
16
+ response = rsolr.select(:q=>'*:*') # sends a request to /solr/select?q=*:*
17
+
18
+ # can also set the request handler path like:
19
+ response = rsolr.send_request('/catalog', :q=>'*:*') # sends a request to /solr/catalog?q=*:*
20
+
21
+ To run tests:
22
+
23
+ Copy an Apache Solr 1.3.0/or later (http://apache.seekmeup.com/lucene/solr/1.3.0/) distribution into this directory and rename to "apache-solr"
24
+ Start Solr HTTP: rake rsolr:start_test_server
25
+ MRI Ruby: rake
26
+ JRuby: jruby -S rake
27
+
28
+ To get a connection in MRI/standard Ruby:
29
+
30
+ solr = RSolr.connect
31
+
32
+ To change the Solr HTTP host:
33
+
34
+ solr = RSolr.connect(:url=>'http://solrserver.com')
35
+
36
+ To get a direct connection (no http) in jRuby using DirectSolrConnection:
37
+
38
+ solr = RSolr.connect({
39
+ :adapter=>:direct,
40
+ :home_dir=>'/path/to/solr/home',
41
+ :dist_dir=>'/path/to/solr/distribution'
42
+ )
43
+
44
+ == Requests
45
+ Once you have a connection, you can execute queries, updates etc..
46
+
47
+ === Querying
48
+ Use the #select method to send requests to the /select handler:
49
+ response = solr.select(:q=>'washington', :facet=>true, 'facet.limit'=>-1, 'facet.field'=>'cat', 'facet.field'=>'inStock', :start=>0, :rows=>10)
50
+
51
+
52
+ === Updating Solr
53
+ Updating is 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".
54
+
55
+ Single document
56
+ response = solr.add(:id=>1, :price=>1.00)
57
+
58
+ Multiple documents
59
+ documents = [{:id=>1, :price=>1.00}, {:id=>2, :price=>10.50}]
60
+ response = solr.add(documents)
61
+
62
+ When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements:
63
+
64
+ doc = {:id=>1, :price=>1.00}
65
+ add_attributes = {:allowDups=>false, :commitWithin=>10.0}
66
+ solr.add(doc, add_attributes) do |doc|
67
+ # boost each document
68
+ doc.attrs[:boost] = 1.5
69
+ # boost the price field:
70
+ doc.field_by_name(:price).attrs[:boost] = 2.0
71
+ end
72
+
73
+ Delete by id
74
+ response = solr.delete_by_id(1)
75
+ or an array of ids
76
+ response = solr.delete_by_id([1, 2, 3, 4])
77
+
78
+ Delete by query:
79
+ response = solr.delete_by_query('price:1.00')
80
+ Delete by array of queries
81
+ response = solr.delete_by_query(['price:1.00', 'price:10.00'])
82
+
83
+
84
+ Commit & Optimize
85
+ solr.commit
86
+ solr.optimize
87
+
88
+
89
+ == Response Formats
90
+ The default response format is Ruby. When the :wt param is set to :ruby, the response is eval'd and wrapped up in a nice Mash (Hash) class. You can get a raw response by setting the :wt to "ruby" - notice, the string -- not a symbol. All other response formats are available as expected, :wt=>'xml' etc..
91
+
92
+ ===XML:
93
+ solr.select(:wt=>:xml)
94
+ ===JSON:
95
+ solr.select(:wt=>:json)
96
+ ===Raw Ruby
97
+ solr.select(:wt=>'ruby')
98
+
99
+ You can access the original request context (path, params, url etc.) by using a block:
100
+ solr.select(:q=>'*:*') do |solr_response, adapter_response|
101
+ adapter_response[:status_code]
102
+ adapter_response[:body]
103
+ adapter_response[:url]
104
+ end
105
+
106
+ The adapter_response is a hash that contains the generated params, url, path, post data, headers etc., very useful for debugging and testing.
107
+
108
+
109
+ == HTTP Client Adapter
110
+ You can specify the http client adapter to use by setting solr.adapter.connector.adapter_name to one of:
111
+ :net_http uses the standard Net::HTTP library
112
+ :curb uses the Ruby "curl" bindings
113
+
114
+ Example:
115
+
116
+ solr.adapter.connector.adapter_name = :curb
117
+
118
+ Example of using the HTTP client only:
119
+
120
+ hclient = RSolr::HTTPClient::Connector.new(:curb).connect(url)
121
+ hclient = RSolr::HTTPClient::Connector.new(:net_http).connect(url)
122
+ hclient.get('/')
123
+
124
+ After reading this http://apocryph.org/2008/11/09/more_indepth_analysis_ruby_http_client_performance - I would recommend using the :curb adapter. NOTE: You can't use the :curb adapter under jRuby. To install curb:
125
+
126
+ sudo gem install curb
data/Rakefile ADDED
@@ -0,0 +1,39 @@
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
+ desc "Run basic tests"
17
+ Rake::TestTask.new("test_units") { |t|
18
+ t.pattern = 'test/**/*_test.rb'
19
+ t.verbose = true
20
+ t.warning = true
21
+ t.libs << "test"
22
+ }
23
+
24
+ # Clean house
25
+ desc 'Clean up tmp files.'
26
+ task :clean do |t|
27
+ FileUtils.rm_rf "doc"
28
+ FileUtils.rm_rf "pkg"
29
+ end
30
+
31
+ # Rdoc
32
+ desc 'Generate documentation for the rsolr gem.'
33
+ Rake::RDocTask.new(:doc) do |rdoc|
34
+ rdoc.rdoc_dir = 'doc'
35
+ rdoc.title = 'Solr-Ruby'
36
+ rdoc.options << '--line-numbers' << '--inline-source'
37
+ rdoc.rdoc_files.include('README.rdoc')
38
+ rdoc.rdoc_files.include('lib/**/*.rb')
39
+ end
@@ -0,0 +1,27 @@
1
+ # Must be executed using jruby
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr')
3
+
4
+ base = File.expand_path( File.dirname(__FILE__) )
5
+ dist = File.join(base, '..', 'apache-solr')
6
+ home = File.join(dist, 'example', 'solr')
7
+
8
+ solr = RSolr.connect(:adapter=>:direct, :home_dir=>home, :dist_dir=>dist)
9
+
10
+ Dir['../apache-solr/example/exampledocs/*.xml'].each do |xml_file|
11
+ puts "Updating with #{xml_file}"
12
+ solr.update File.read(xml_file)
13
+ end
14
+
15
+ puts
16
+
17
+ response = solr.select :q=>'ipod', :fq=>'price:[0 TO 50]', :rows=>2, :start=>0
18
+
19
+ docs = response[:response][:docs]
20
+
21
+ docs.each do |doc|
22
+ puts doc[:timestamp]
23
+ end
24
+
25
+ solr.delete_by_query('*:*') and solr.commit
26
+
27
+ solr.adapter.close
data/examples/http.rb ADDED
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr')
2
+
3
+ solr = RSolr.connect
4
+
5
+ # switch out the http adapter from curb to net_http (just for an example)
6
+ solr.adapter.connector.adapter_name = :curb
7
+
8
+ Dir['../apache-solr/example/exampledocs/*.xml'].each do |xml_file|
9
+ puts "Updating with #{xml_file}"
10
+ solr.update File.read(xml_file)
11
+ end
12
+
13
+ puts
14
+
15
+ solr.select(:q=>'ipod', :fq=>'price:[0 TO 50]', :rows=>2, :start=>0) do |solr_response,adapter_response|
16
+ puts "URL : #{adapter_response[:url]}"
17
+ solr_response[:response][:docs].each do |doc|
18
+ puts doc[:timestamp]
19
+ end
20
+ end
21
+
22
+ solr.delete_by_query('*:*') and solr.commit
data/lib/core_ext.rb ADDED
@@ -0,0 +1,25 @@
1
+ #class Symbol
2
+
3
+ # allow symbol chaining: :one.two.three
4
+ # This breaks Rails, probably lots of other things too :(
5
+ #def method_missing(m)
6
+ # [self.to_s, m.to_s].join('.').to_sym
7
+ #end
8
+
9
+ #end
10
+
11
+ class Hash
12
+
13
+ def to_mash
14
+ self.is_a?(Mash) ? self : Mash.new(self)
15
+ end
16
+
17
+ end
18
+
19
+ unless Array.respond_to?(:extract_options!)
20
+ class Array
21
+ def extract_options!
22
+ last.is_a?(::Hash) ? pop : {}
23
+ end
24
+ end
25
+ end