mwmitchell-solr 0.5.4 → 0.5.5
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 +18 -0
- data/README.rdoc +11 -5
- data/examples/direct.rb +5 -1
- data/examples/http.rb +5 -1
- data/lib/solr.rb +1 -2
- data/lib/solr/connection/base.rb +1 -1
- data/lib/solr/connection/search_ext.rb +1 -1
- data/lib/solr/http_client.rb +7 -7
- data/lib/solr/response/base.rb +2 -1
- data/lib/solr/response/query.rb +10 -7
- data/test/connection/test_methods.rb +25 -0
- metadata +1 -1
data/CHANGES.txt
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
0.5.5 - December 29, 2008
|
2
|
+
|
3
|
+
Fixed bug where accessing a field by method name failed:
|
4
|
+
|
5
|
+
docs.each do |doc|
|
6
|
+
doc.timestamp
|
7
|
+
end
|
8
|
+
|
9
|
+
Fixed bug where using the #has? method on a doc failed:
|
10
|
+
|
11
|
+
docs.each do |doc|
|
12
|
+
doc.has?('timestamp')
|
13
|
+
end
|
14
|
+
|
15
|
+
Removed invalid autoload in Solr module
|
16
|
+
|
17
|
+
Fixed spelling error in Solr::Connection::SearchExt (thanks to matthewrudy)
|
18
|
+
|
1
19
|
0.5.4 - December 29, 2008
|
2
20
|
|
3
21
|
Re-organized the main Solr adapters, they're now in Solr::Connection::Adapter instead of Solr::Adapter
|
data/README.rdoc
CHANGED
@@ -27,9 +27,11 @@ Once you have a connection, you can execute queries, updates etc..
|
|
27
27
|
|
28
28
|
|
29
29
|
=== Querying
|
30
|
-
response = solr.query(:q=>'washington', :facet=>true, :facet.limit=>-1, :facet.field=>cat, :facet.field=>inStock)
|
30
|
+
response = solr.query(:q=>'washington', :facet=>true, :facet.limit=>-1, :facet.field=>'cat', :facet.field=>'inStock')
|
31
31
|
response = solr.find_by_id(1)
|
32
32
|
|
33
|
+
* thanks to a little Ruby magic, we can chain symbols to create Solr "dot" syntax: :facet.field=>'cat'
|
34
|
+
|
33
35
|
Using the #search method makes building more complex Solr queries easier:
|
34
36
|
|
35
37
|
response = solr.search 'my search', :filters=>{:price=>(0.00..10.00)}
|
@@ -167,18 +169,22 @@ Solr (ruby) comes with a simple indexer that makes use of the Solr mapper. Here'
|
|
167
169
|
|
168
170
|
solr = Solr.connect(:http)
|
169
171
|
i = Solr::Indexer.new(solr, mapping)
|
170
|
-
i.index(
|
172
|
+
i.index(mapped_data)
|
171
173
|
|
172
174
|
|
173
175
|
==HTTP Client Adapter
|
174
|
-
You can specify the Ruby http client to use by setting Solr::Adapter::HTTP.client_adapter to one of:
|
176
|
+
You can specify the Ruby http client to use by setting Solr::Connection::Adapter::HTTP.client_adapter to one of:
|
175
177
|
:net_http uses the standard Net::HTTP library
|
176
178
|
:curb uses the Ruby "curl" bindings
|
177
179
|
|
178
180
|
Example:
|
179
181
|
|
180
|
-
|
181
|
-
|
182
|
+
Solr::Connection::Adapter::HTTP.client_adapter = :curb
|
183
|
+
|
184
|
+
Example of using the HTTP client only:
|
185
|
+
|
186
|
+
hclient = Solr::HTTPClient.connect(url, :curb)
|
187
|
+
hclient = Solr::HTTPClient.connect(url, :net_http)
|
182
188
|
|
183
189
|
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:
|
184
190
|
|
data/examples/direct.rb
CHANGED
data/examples/http.rb
CHANGED
data/lib/solr.rb
CHANGED
@@ -7,12 +7,11 @@ proc {|base, files|
|
|
7
7
|
|
8
8
|
module Solr
|
9
9
|
|
10
|
-
VERSION = '0.5.
|
10
|
+
VERSION = '0.5.5'
|
11
11
|
|
12
12
|
autoload :Message, 'solr/message'
|
13
13
|
autoload :Response, 'solr/response'
|
14
14
|
autoload :Connection, 'solr/connection'
|
15
|
-
autoload :Ext, 'solr/ext'
|
16
15
|
autoload :Mapper, 'solr/mapper'
|
17
16
|
autoload :Indexer, 'solr/indexer'
|
18
17
|
autoload :HTTPClient, 'solr/http_client'
|
data/lib/solr/connection/base.rb
CHANGED
@@ -14,7 +14,7 @@ module Solr::Connection::SearchExt
|
|
14
14
|
params.merge!({:facet => true})
|
15
15
|
params.merge! build_facets(facets)
|
16
16
|
elsif facets.is_a?(Hash)
|
17
|
-
params.
|
17
|
+
params.merge!({:facet => true})
|
18
18
|
#params += build_facet(facets)
|
19
19
|
elsif facets.is_a?(String)
|
20
20
|
#params += facets
|
data/lib/solr/http_client.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
require 'uri'
|
1
|
+
#require 'uri'
|
2
2
|
|
3
|
-
# A simple wrapper for different http client implementations
|
4
|
-
#
|
3
|
+
# A simple wrapper for different http client implementations.
|
4
|
+
# Supports #get and #post
|
5
5
|
# This was motivated by: http://apocryph.org/2008/11/09/more_indepth_analysis_ruby_http_client_performance/
|
6
6
|
# Net::HTTP is the default adapter
|
7
7
|
|
@@ -15,10 +15,10 @@ require 'uri'
|
|
15
15
|
# :headers
|
16
16
|
|
17
17
|
# Example:
|
18
|
-
#hclient = Solr::HTTPClient.connect('http://www.google.com', :net_http)
|
19
|
-
#response = hclient.get('/search', :hl=>:en, :q=>:ruby, :btnG=>:Search)
|
20
|
-
#puts response[:status_code]
|
21
|
-
#puts response[:body]
|
18
|
+
# hclient = Solr::HTTPClient.connect('http://www.google.com', :net_http)
|
19
|
+
# response = hclient.get('/search', :hl=>:en, :q=>:ruby, :btnG=>:Search)
|
20
|
+
# puts response[:status_code]
|
21
|
+
# puts response[:body]
|
22
22
|
|
23
23
|
module Solr::HTTPClient
|
24
24
|
|
data/lib/solr/response/base.rb
CHANGED
data/lib/solr/response/query.rb
CHANGED
@@ -1,23 +1,26 @@
|
|
1
1
|
# response module for queries
|
2
2
|
module Solr::Response::Query
|
3
3
|
|
4
|
-
# module for adding
|
4
|
+
# module for adding helper methods to each Hash document
|
5
5
|
module DocExt
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def self.extended(base)
|
8
|
+
base.keys.each do |k,v|
|
9
|
+
base.instance_eval <<-EOF
|
10
|
+
def #{k}; self['#{k.to_s}']; end
|
11
|
+
EOF
|
12
|
+
end
|
12
13
|
end
|
13
14
|
|
14
|
-
# Helper method to check if value/values exist for a given key.
|
15
|
+
# Helper method to check if value/multi-values exist for a given key.
|
15
16
|
# The value can be a string, or a RegExp
|
16
17
|
# Example:
|
18
|
+
# doc.has?(:location_facet)
|
17
19
|
# doc.has?(:location_facet, 'Clemons')
|
18
20
|
# doc.has?(:id, 'h009', /^u/i)
|
19
21
|
def has?(k, *values)
|
20
22
|
return if self[k].nil?
|
23
|
+
return true if self.has_key?(k) and values.empty?
|
21
24
|
target = self[k]
|
22
25
|
if target.is_a?(Array)
|
23
26
|
values.each do |val|
|
@@ -56,6 +56,31 @@ module ConnectionTestMethods
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_query_response_docs
|
60
|
+
@solr.add(:id=>1, :price=>1.00, :cat=>['electronics', 'something else'])
|
61
|
+
@solr.commit
|
62
|
+
r = @solr.query(:q=>'*:*')
|
63
|
+
assert r.is_a?(Solr::Response::Query::Base)
|
64
|
+
assert_equal Array, r.docs.class
|
65
|
+
first = r.docs.first
|
66
|
+
assert first.respond_to?(:price)
|
67
|
+
assert first.respond_to?(:cat)
|
68
|
+
assert first.respond_to?(:id)
|
69
|
+
assert first.respond_to?(:timestamp)
|
70
|
+
|
71
|
+
# test the has? method
|
72
|
+
assert first.has?('price', 1.00)
|
73
|
+
assert first.has?('cat', 'electronics')
|
74
|
+
assert first.has?('cat', 'something else')
|
75
|
+
|
76
|
+
assert first.has?('cat', /something/)
|
77
|
+
|
78
|
+
# has? only works with strings at this time
|
79
|
+
assert_nil first.has?(:cat)
|
80
|
+
|
81
|
+
assert false == first.has?('cat', /zxcv/)
|
82
|
+
end
|
83
|
+
|
59
84
|
def test_add
|
60
85
|
assert_equal 0, @solr.query(:q=>'*:*').total
|
61
86
|
response = @solr.add(:id=>100)
|