mwmitchell-rsolr 0.5.9 → 0.6.1
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 +10 -0
- data/LICENSE +0 -0
- data/README.rdoc +11 -14
- data/Rakefile +0 -0
- data/examples/direct.rb +0 -0
- data/examples/http.rb +0 -0
- data/lib/core_ext.rb +0 -0
- data/lib/mash.rb +0 -0
- data/lib/rsolr/connection/adapter/common_methods.rb +0 -0
- data/lib/rsolr/connection/adapter/direct.rb +0 -0
- data/lib/rsolr/connection/adapter/http.rb +0 -0
- data/lib/rsolr/connection/adapter.rb +0 -0
- data/lib/rsolr/connection/base.rb +19 -20
- data/lib/rsolr/connection.rb +0 -1
- data/lib/rsolr/http_client/adapter/curb.rb +0 -0
- data/lib/rsolr/http_client/adapter/net_http.rb +0 -0
- data/lib/rsolr/http_client/adapter.rb +0 -0
- data/lib/rsolr/http_client.rb +0 -0
- data/lib/rsolr/indexer.rb +0 -0
- data/lib/rsolr/mapper/rss.rb +0 -0
- data/lib/rsolr/mapper.rb +0 -0
- data/lib/rsolr/message.rb +0 -0
- data/lib/rsolr/response/base.rb +0 -0
- data/lib/rsolr/response/index_info.rb +0 -0
- data/lib/rsolr/response/query.rb +0 -0
- data/lib/rsolr/response/update.rb +0 -0
- data/lib/rsolr/response.rb +0 -0
- data/lib/rsolr.rb +4 -3
- data/test/connection/direct_test.rb +1 -1
- data/test/connection/http_test.rb +1 -1
- data/test/connection/test_methods.rb +2 -2
- data/test/http_client/curb_test.rb +0 -0
- data/test/http_client/net_http_test.rb +0 -0
- data/test/http_client/test_methods.rb +0 -0
- data/test/http_client/util_test.rb +0 -0
- data/test/mapper_test.rb +0 -0
- data/test/message_test.rb +0 -0
- data/test/response/base_test.rb +0 -0
- data/test/response/pagination_test.rb +3 -3
- data/test/response/query_test.rb +0 -0
- data/test/ruby-lang.org.rss.xml +0 -0
- data/test/test_helpers.rb +0 -0
- metadata +1 -3
- data/lib/rsolr/connection/search_ext.rb +0 -134
- data/test/response/search_ext_test.rb +0 -19
data/CHANGES.txt
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
0.6.1 - January 13, 2009
|
2
|
+
Removed SearchExt and mapping until this library gets some real use
|
3
|
+
The only param mapping now is for :page and :per_page via the #search method
|
4
|
+
The Connection::Base #query method does NO mapping now
|
5
|
+
|
6
|
+
0.6.0 - January 9, 2009
|
7
|
+
Removed first argument from RSolr.connect, the "adapter_name"
|
8
|
+
The adapter is now set using the :adapter key when passing in options to RSolr.connect:
|
9
|
+
s = RSolr.connect(:adapter=>:direct)
|
10
|
+
|
1
11
|
0.5.9 - January 7, 2009
|
2
12
|
Finally brought in the ExtLib Mash classes for incoming params and response hashes from solr
|
3
13
|
- this gives the ability to access/set values for hashes using strings OR symbols (HashWithIndifferentAccess)
|
data/LICENSE
CHANGED
File without changes
|
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ A Ruby client for Apache Solr. Has transparent JRuby support by using "org.apach
|
|
9
9
|
Simple usage:
|
10
10
|
require 'rubygems'
|
11
11
|
require 'rsolr'
|
12
|
-
rsolr = RSolr.connect
|
12
|
+
rsolr = RSolr.connect
|
13
13
|
response = rsolr.query(:q=>'*:*')
|
14
14
|
|
15
15
|
|
@@ -22,15 +22,15 @@ To run tests:
|
|
22
22
|
|
23
23
|
To get a connection in MRI/standard Ruby:
|
24
24
|
|
25
|
-
solr = RSolr.connect
|
25
|
+
solr = RSolr.connect
|
26
26
|
|
27
27
|
To get a direct connection (no http) in jRuby using DirectSolrConnection:
|
28
28
|
|
29
|
-
solr = RSolr.connect(:direct, :home_dir=>'/path/to/solr/home', :dist_dir=>'/path/to/solr/distribution')
|
29
|
+
solr = RSolr.connect(:adapter=>:direct, :home_dir=>'/path/to/solr/home', :dist_dir=>'/path/to/solr/distribution')
|
30
30
|
|
31
31
|
You can set RSolr params that will be sent on every request:
|
32
32
|
|
33
|
-
solr = RSolr.connect(:
|
33
|
+
solr = RSolr.connect(:global_params=>{:wt=>:ruby, :echoParams=>'EXPLICIT'})
|
34
34
|
|
35
35
|
|
36
36
|
== Requests
|
@@ -38,22 +38,17 @@ Once you have a connection, you can execute queries, updates etc..
|
|
38
38
|
|
39
39
|
|
40
40
|
=== Querying
|
41
|
+
Use the #query method to send requests to Solr as-is (no param mapping)
|
42
|
+
Use the #search method to take advantage of some of the param mapping (currently only :page and :per_page)
|
41
43
|
response = solr.query(:q=>'washington', :facet=>true, :facet.limit=>-1, :facet.field=>'cat', :facet.field=>'inStock')
|
42
44
|
response = solr.find_by_id(1)
|
43
45
|
|
44
46
|
Thanks to a little Ruby magic, we can chain symbols to create Solr "dot" syntax: :facet.field=>'cat'
|
45
47
|
|
46
|
-
Using the #search method makes building more complex Solr queries easier:
|
47
|
-
|
48
|
-
response = solr.search 'my search', :filters=>{:price=>(0.00..10.00)}
|
49
|
-
response.docs.each do |doc|
|
50
|
-
doc[:price]
|
51
|
-
end
|
52
|
-
|
53
48
|
====Pagination
|
54
|
-
Pagination is simplified by using the :page and :per_page params:
|
49
|
+
Pagination is simplified by using the :page and :per_page params when using the #search method:
|
55
50
|
|
56
|
-
response = solr.
|
51
|
+
response = solr.search(:page=>1, :per_page=>10, :q=>'*:*')
|
57
52
|
response.per_page
|
58
53
|
response.total_pages
|
59
54
|
response.current_page
|
@@ -64,7 +59,9 @@ If you use WillPaginate, just pass-in the response to the #will_paginate view he
|
|
64
59
|
|
65
60
|
<%= will_paginate(@response) %>
|
66
61
|
|
67
|
-
The #
|
62
|
+
The #search method automatically figure out the :start and :rows value, based on the values of :page and :per_page. The will_paginate view helper just needs the right methods (#current_page, #previous_page, #next_page and #total_pages) to create the pagination view widget.
|
63
|
+
|
64
|
+
The #search method will be providing more param mapping, but not until RSolr gets more use. If you have ideas for a param mapping interface, let me know!
|
68
65
|
|
69
66
|
|
70
67
|
=== Updating Solr
|
data/Rakefile
CHANGED
File without changes
|
data/examples/direct.rb
CHANGED
File without changes
|
data/examples/http.rb
CHANGED
File without changes
|
data/lib/core_ext.rb
CHANGED
File without changes
|
data/lib/mash.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,8 +5,6 @@ class RSolr::Connection::Base
|
|
5
5
|
|
6
6
|
attr_reader :adapter, :opts
|
7
7
|
|
8
|
-
include RSolr::Connection::SearchExt
|
9
|
-
|
10
8
|
# "adapter" is instance of:
|
11
9
|
# RSolr::Adapter::HTTP
|
12
10
|
# RSolr::Adapter::Direct (jRuby only)
|
@@ -25,19 +23,26 @@ class RSolr::Connection::Base
|
|
25
23
|
# sets default params etc.. - could be used as a mapping hook
|
26
24
|
# type of request should be passed in here? -> map_params(:query, {})
|
27
25
|
def map_params(params)
|
28
|
-
opts[:global_params].
|
26
|
+
{}.merge(@opts[:global_params]).merge(params).to_mash
|
29
27
|
end
|
30
28
|
|
31
|
-
# send request to the select handler
|
29
|
+
# send request (no param mapping) to the select handler
|
32
30
|
# params is hash with valid solr request params (:q, :fl, :qf etc..)
|
33
31
|
# if params[:wt] is not set, the default is :ruby (see opts[:global_params])
|
34
32
|
# if :wt is something other than :ruby, the raw response body is returned
|
35
33
|
# otherwise, an instance of RSolr::Response::Query is returned
|
36
34
|
# NOTE: to get raw ruby, use :wt=>'ruby'
|
35
|
+
# There is NO param mapping here, what you put it is what gets sent to Solr
|
37
36
|
def query(params)
|
38
|
-
|
39
|
-
response = @adapter.query(
|
40
|
-
|
37
|
+
p = map_params(params)
|
38
|
+
response = @adapter.query(p)
|
39
|
+
p[:wt]==:ruby ? RSolr::Response::Query::Base.new(response) : response
|
40
|
+
end
|
41
|
+
|
42
|
+
# same as the #query method, but with additional param mapping
|
43
|
+
# currently only :page and :per_page
|
44
|
+
def search(params)
|
45
|
+
self.query(modify_params_for_pagination(params))
|
41
46
|
end
|
42
47
|
|
43
48
|
# Finds a document by its id
|
@@ -103,19 +108,13 @@ class RSolr::Connection::Base
|
|
103
108
|
RSolr::Message
|
104
109
|
end
|
105
110
|
|
106
|
-
def modify_params_for_pagination(
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
params
|
114
|
-
end
|
115
|
-
|
116
|
-
def calculate_start(current_page, per_page)
|
117
|
-
page = current_page > 0 ? current_page : 1
|
118
|
-
(page - 1) * per_page
|
111
|
+
def modify_params_for_pagination(p)
|
112
|
+
per_page = p.delete(:per_page).to_s.to_i
|
113
|
+
p[:rows] = per_page==0 ? 10 : per_page
|
114
|
+
page = p.delete(:page).to_s.to_i
|
115
|
+
page = page > 0 ? page : 1
|
116
|
+
p[:start] = (page - 1) * (p[:rows] || 0)
|
117
|
+
p
|
119
118
|
end
|
120
119
|
|
121
120
|
end
|
data/lib/rsolr/connection.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/lib/rsolr/http_client.rb
CHANGED
File without changes
|
data/lib/rsolr/indexer.rb
CHANGED
File without changes
|
data/lib/rsolr/mapper/rss.rb
CHANGED
File without changes
|
data/lib/rsolr/mapper.rb
CHANGED
File without changes
|
data/lib/rsolr/message.rb
CHANGED
File without changes
|
data/lib/rsolr/response/base.rb
CHANGED
File without changes
|
File without changes
|
data/lib/rsolr/response/query.rb
CHANGED
File without changes
|
File without changes
|
data/lib/rsolr/response.rb
CHANGED
File without changes
|
data/lib/rsolr.rb
CHANGED
@@ -7,7 +7,7 @@ proc {|base, files|
|
|
7
7
|
|
8
8
|
module RSolr
|
9
9
|
|
10
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.6.0'
|
11
11
|
|
12
12
|
autoload :Message, 'rsolr/message'
|
13
13
|
autoload :Response, 'rsolr/response'
|
@@ -17,10 +17,11 @@ module RSolr
|
|
17
17
|
autoload :HTTPClient, 'rsolr/http_client'
|
18
18
|
|
19
19
|
# factory for creating connections
|
20
|
-
# adapter
|
20
|
+
# opts[:adapter] is either :http or :direct
|
21
21
|
# opts are sent to the adapter instance (:url for http, :dist_dir for :direct etc.)
|
22
22
|
# and to the connection instance
|
23
|
-
def self.connect(
|
23
|
+
def self.connect(opts={})
|
24
|
+
adapter_name = opts[:adapter] ||= :http
|
24
25
|
types = {
|
25
26
|
:http=>'HTTP',
|
26
27
|
:direct=>'Direct'
|
@@ -12,7 +12,7 @@ class ConnectionDirectTest < RSolrBaseTest
|
|
12
12
|
base = File.expand_path( File.dirname(__FILE__) )
|
13
13
|
dist = File.join(base, '..', '..', 'apache-solr')
|
14
14
|
home = File.join(dist, 'example', 'solr')
|
15
|
-
@solr = RSolr.connect(:direct, :home_dir=>home, :dist_dir=>dist)
|
15
|
+
@solr = RSolr.connect(:adapter=>:direct, :home_dir=>home, :dist_dir=>dist)
|
16
16
|
@solr.delete_by_query('*:*')
|
17
17
|
@solr.commit
|
18
18
|
end
|
@@ -22,13 +22,13 @@ module ConnectionTestMethods
|
|
22
22
|
|
23
23
|
# setting adapter options in Solr.connect method should set them in the adapter
|
24
24
|
def test_set_adapter_options
|
25
|
-
solr = RSolr.connect(:
|
25
|
+
solr = RSolr.connect(:select_path=>'/select2')
|
26
26
|
assert_equal '/select2', solr.adapter.opts[:select_path]
|
27
27
|
end
|
28
28
|
|
29
29
|
# setting connection options in Solr.connect method should set them in the connection
|
30
30
|
def test_set_connection_options
|
31
|
-
solr = RSolr.connect(:
|
31
|
+
solr = RSolr.connect(:default_wt=>:json)
|
32
32
|
assert_equal :json, solr.opts[:default_wt]
|
33
33
|
end
|
34
34
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/mapper_test.rb
CHANGED
File without changes
|
data/test/message_test.rb
CHANGED
File without changes
|
data/test/response/base_test.rb
CHANGED
File without changes
|
@@ -11,9 +11,9 @@ class ResponsePaginationTest < RSolrBaseTest
|
|
11
11
|
# test the Solr::Connection pagination methods
|
12
12
|
def test_connection_calculate_start
|
13
13
|
dummy_connection = RSolr::Connection::Base.new(nil)
|
14
|
-
assert_equal 15, dummy_connection.send(:calculate_start, 2, 15)
|
15
|
-
assert_equal 450, dummy_connection.send(:calculate_start, 10, 50)
|
16
|
-
assert_equal 0, dummy_connection.send(:calculate_start, 0, 50)
|
14
|
+
#assert_equal 15, dummy_connection.send(:calculate_start, 2, 15)
|
15
|
+
#assert_equal 450, dummy_connection.send(:calculate_start, 10, 50)
|
16
|
+
#assert_equal 0, dummy_connection.send(:calculate_start, 0, 50)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_connection_modify_params_for_pagination
|
data/test/response/query_test.rb
CHANGED
File without changes
|
data/test/ruby-lang.org.rss.xml
CHANGED
File without changes
|
data/test/test_helpers.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mwmitchell-rsolr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Mitchell
|
@@ -43,7 +43,6 @@ files:
|
|
43
43
|
- lib/rsolr/connection/adapter/http.rb
|
44
44
|
- lib/rsolr/connection/adapter.rb
|
45
45
|
- lib/rsolr/connection/base.rb
|
46
|
-
- lib/rsolr/connection/search_ext.rb
|
47
46
|
- lib/rsolr/connection.rb
|
48
47
|
- lib/rsolr/http_client/adapter/curb.rb
|
49
48
|
- lib/rsolr/http_client/adapter/net_http.rb
|
@@ -104,7 +103,6 @@ test_files:
|
|
104
103
|
- test/response/base_test.rb
|
105
104
|
- test/response/pagination_test.rb
|
106
105
|
- test/response/query_test.rb
|
107
|
-
- test/response/search_ext_test.rb
|
108
106
|
- test/rsolr_test
|
109
107
|
- test/ruby-lang.org.rss.xml
|
110
108
|
- test/test_helpers.rb
|
@@ -1,134 +0,0 @@
|
|
1
|
-
module RSolr::Connection::SearchExt
|
2
|
-
|
3
|
-
# TODO : clean this thing up dude
|
4
|
-
|
5
|
-
def search(params={})
|
6
|
-
params = params.to_mash
|
7
|
-
if params[:fields]
|
8
|
-
fields = params.delete :fields
|
9
|
-
params[:fl] = fields.is_a?(Array) ? fields.join(' ') : fields
|
10
|
-
end
|
11
|
-
|
12
|
-
# adds quoted values to the :filters hash
|
13
|
-
if params[:phrase_filters]
|
14
|
-
phrase_filters = params.delete(:phrase_filters)
|
15
|
-
params[:filters] ||= {}
|
16
|
-
phrase_filters.each do |filter,values|
|
17
|
-
values = [values] unless values.is_a?(Array)
|
18
|
-
params[:filters][filter] ||= []
|
19
|
-
params[:filters][filter] = [params[:filters][filter]] unless params[:filters][filter].is_a?(Array)
|
20
|
-
values.each do |v|
|
21
|
-
params[:filters][filter] << %(\"#{v}\")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
if params[:filters]
|
27
|
-
filter_params = params.delete(:filters)
|
28
|
-
params[:fq] = build_filters(filter_params)
|
29
|
-
end
|
30
|
-
facets = params.delete(:facets) if params[:facets]
|
31
|
-
|
32
|
-
if facets
|
33
|
-
if facets.is_a?(Array)
|
34
|
-
params.merge!({:facet => true})
|
35
|
-
params.merge! build_facets(facets)
|
36
|
-
elsif facets.is_a?(Hash)
|
37
|
-
params.merge!({:facet => true})
|
38
|
-
#params += build_facet(facets)
|
39
|
-
elsif facets.is_a?(String)
|
40
|
-
#params += facets
|
41
|
-
else
|
42
|
-
raise 'facets must either be a Hash or an Array'
|
43
|
-
end
|
44
|
-
end
|
45
|
-
#params[:qt] ||= :dismax
|
46
|
-
params[:q] = build_query(params[:q])
|
47
|
-
self.query params
|
48
|
-
end
|
49
|
-
|
50
|
-
protected
|
51
|
-
|
52
|
-
# returns the query param
|
53
|
-
def build_query(queries)
|
54
|
-
query_string = ''
|
55
|
-
case queries
|
56
|
-
when String
|
57
|
-
query_string = queries
|
58
|
-
when Array
|
59
|
-
query_string = queries.join(' ')
|
60
|
-
when Hash
|
61
|
-
query_string_array = []
|
62
|
-
queries.each do |k,v|
|
63
|
-
if v.is_a?(Array) # add a filter for each value
|
64
|
-
v.each do |val|
|
65
|
-
query_string_array << "#{k}:#{val}"
|
66
|
-
end
|
67
|
-
elsif v.is_a?(Range)
|
68
|
-
query_string_array << "#{k}:[#{v.min} TO #{v.max}]"
|
69
|
-
else
|
70
|
-
query_string_array << "#{k}:#{v}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
query_string = query_string_array.join(' ')
|
74
|
-
end
|
75
|
-
query_string
|
76
|
-
end
|
77
|
-
|
78
|
-
def build_filters(filters)
|
79
|
-
params = []
|
80
|
-
# handle "ruby-ish" filters
|
81
|
-
case filters
|
82
|
-
when String
|
83
|
-
params << filters
|
84
|
-
when Array
|
85
|
-
filters.each { |f| params << f }
|
86
|
-
when Hash
|
87
|
-
filters.each do |k,v|
|
88
|
-
if v.is_a?(Array) # add a filter for each value
|
89
|
-
v.each do |val|
|
90
|
-
params << "#{k}:#{val}"
|
91
|
-
end
|
92
|
-
elsif v.is_a?(Range)
|
93
|
-
params << "#{k}:[#{v.min} TO #{v.max}]"
|
94
|
-
else
|
95
|
-
params << "#{k}:#{v}"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
params
|
100
|
-
end
|
101
|
-
|
102
|
-
def build_facets(facet_array)
|
103
|
-
facet_array.inject({}) do |p, facet_hash|
|
104
|
-
build_facet(facet_hash).each {|k| p.merge!(k) }
|
105
|
-
p
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def build_facet(facet_hash)
|
110
|
-
params = []
|
111
|
-
facet_name = facet_hash['name'] || facet_hash[:name]
|
112
|
-
facet_hash.each do |k,v|
|
113
|
-
# handle some cases specially
|
114
|
-
if 'field' == k.to_s
|
115
|
-
params << {"facet.field" => v}
|
116
|
-
elsif 'query' == k.to_s
|
117
|
-
q = build_query(v)
|
118
|
-
params << {"facet.query"=>q}
|
119
|
-
if facet_name
|
120
|
-
# keep track of names => facet_queries
|
121
|
-
name_to_facet_query[facet_name] = q['facet.query']
|
122
|
-
end
|
123
|
-
else
|
124
|
-
params << {"f.#{facet_hash[:field]}.facet.#{k}" => v}
|
125
|
-
end
|
126
|
-
end
|
127
|
-
params
|
128
|
-
end
|
129
|
-
|
130
|
-
def name_to_facet_query
|
131
|
-
@name_to_facet_query ||= {}
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helpers')
|
2
|
-
|
3
|
-
class ResponseSearchExtTest < RSolrBaseTest
|
4
|
-
|
5
|
-
def test_facet_response_methods
|
6
|
-
=begin
|
7
|
-
@response.facets
|
8
|
-
@response.facet_fields
|
9
|
-
@response.facet_queries
|
10
|
-
@response.facet_fields_by_hash
|
11
|
-
@response.facet_field(:feed_language_facet)
|
12
|
-
@response.facet_field_values(:feed_language_facet)
|
13
|
-
@response.facet_field_by_hash(:feed_language_facet)
|
14
|
-
@response.facet_field_by_hash(:feed_language_facet)
|
15
|
-
@response.facet_field_count(:feed_title_facet, 'ScienceDaily: Latest Science News')
|
16
|
-
=end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|