rsolr-ext 0.9.6.5 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -15
- data/lib/rsolr-ext/request.rb +0 -11
- data/lib/rsolr-ext/response/docs.rb +0 -44
- data/lib/rsolr-ext.rb +8 -0
- data/rsolr-ext.gemspec +3 -3
- data/test/connection_test.rb +1 -1
- data/test/request_test.rb +2 -2
- data/test/response_test.rb +0 -31
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -25,13 +25,6 @@ The #luke method returns a Hash/Mash result of a /admin/luke?numTerms=0 request:
|
|
25
25
|
===#find
|
26
26
|
The #find method listens for certain keys. All other keys are ignored, allowing the ability to mix-and-match special keys with normal Solr param keys. The recognized keys are describe below.
|
27
27
|
|
28
|
-
|
29
|
-
:page - This maps to the Solr "start" param. The current "page" in the results set. RSolr::Ext handles the page-to-rows math for you.
|
30
|
-
|
31
|
-
|
32
|
-
:per_page - This maps to the Solr "rows" param. How many "pages" in the result.
|
33
|
-
|
34
|
-
|
35
28
|
:queries - This key maps to the Solr "q" param. Accepts a string, array or hash. When an array is used, each value is joined by a space. When a hash is used, the keys are used as Solr fields.
|
36
29
|
|
37
30
|
* :queries => 'normal' BECOMES ?q=normal
|
@@ -73,8 +66,6 @@ The #find method listens for certain keys. All other keys are ignored, allowing
|
|
73
66
|
==Request Example
|
74
67
|
solr = RSolr::Ext.connect
|
75
68
|
solr_params = {
|
76
|
-
:page=>2,
|
77
|
-
:per_page=>10,
|
78
69
|
:phrases=>{:name=>'This is a phrase'},
|
79
70
|
:filters=>['test', {:price=>(1..10)}],
|
80
71
|
:phrase_filters=>{:manu=>['Apple']},
|
@@ -94,8 +85,6 @@ RSolr::Ext decorates the normal output hash from RSolr and adds some helpful met
|
|
94
85
|
response.ok?
|
95
86
|
response.params
|
96
87
|
response.docs
|
97
|
-
response.docs.previous_page
|
98
|
-
response.docs.next_page
|
99
88
|
response.facets.each do |facet|
|
100
89
|
puts facet.name
|
101
90
|
facet.items.each do |item|
|
@@ -105,10 +94,6 @@ RSolr::Ext decorates the normal output hash from RSolr and adds some helpful met
|
|
105
94
|
|
106
95
|
You can access values in the response hash using symbols or strings.
|
107
96
|
|
108
|
-
===Documents/Pagination
|
109
|
-
If you wanna paginate, just throw the collection into the WillPaginate view helper.
|
110
|
-
<%= will_paginate response.docs %>
|
111
|
-
|
112
97
|
==The "Model" Module
|
113
98
|
You can create your own <read-only> "models" using RSolr::Ext::Model
|
114
99
|
|
data/lib/rsolr-ext/request.rb
CHANGED
@@ -4,17 +4,6 @@ module RSolr::Ext::Request
|
|
4
4
|
|
5
5
|
def map input
|
6
6
|
output = {}
|
7
|
-
if input[:per_page]
|
8
|
-
output[:rows] = input.delete(:per_page).to_i
|
9
|
-
end
|
10
|
-
|
11
|
-
if page = input.delete(:page)
|
12
|
-
raise ':per_page must be set when using :page' unless output[:rows]
|
13
|
-
page = page.to_s.to_i-1
|
14
|
-
page = page < 1 ? 0 : page
|
15
|
-
output[:start] = page * output[:rows]
|
16
|
-
end
|
17
|
-
|
18
7
|
if queries = input.delete(:queries)
|
19
8
|
output[:q] = append_to_param output[:q], build_query(queries, false)
|
20
9
|
end
|
@@ -1,52 +1,8 @@
|
|
1
1
|
module RSolr::Ext::Response::Docs
|
2
2
|
|
3
|
-
module Pageable
|
4
|
-
|
5
|
-
attr_accessor :start, :per_page, :total
|
6
|
-
|
7
|
-
# Returns the current page calculated from 'rows' and 'start'
|
8
|
-
# WillPaginate hook
|
9
|
-
def current_page
|
10
|
-
return 1 if start < 1
|
11
|
-
per_page_normalized = per_page < 1 ? 1 : per_page
|
12
|
-
@current_page ||= (start / per_page_normalized).ceil + 1
|
13
|
-
end
|
14
|
-
|
15
|
-
# Calcuates the total pages from 'numFound' and 'rows'
|
16
|
-
# WillPaginate hook
|
17
|
-
def total_pages
|
18
|
-
@total_pages ||= per_page > 0 ? (total / per_page.to_f).ceil : 1
|
19
|
-
end
|
20
|
-
|
21
|
-
# returns the previous page number or 1
|
22
|
-
# WillPaginate hook
|
23
|
-
def previous_page
|
24
|
-
@previous_page ||= (current_page > 1) ? current_page - 1 : 1
|
25
|
-
end
|
26
|
-
|
27
|
-
# returns the next page number or the last
|
28
|
-
# WillPaginate hook
|
29
|
-
def next_page
|
30
|
-
@next_page ||= (current_page == total_pages) ? total_pages : current_page+1
|
31
|
-
end
|
32
|
-
|
33
|
-
def has_next?
|
34
|
-
current_page < total_pages
|
35
|
-
end
|
36
|
-
|
37
|
-
def has_previous?
|
38
|
-
current_page > 1
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
3
|
def self.extended(base)
|
44
4
|
d = base['response']['docs']
|
45
5
|
d.each{|doc| doc.extend RSolr::Ext::Doc }
|
46
|
-
d.extend Pageable
|
47
|
-
d.per_page = base['responseHeader']['params']['rows'].to_s.to_i
|
48
|
-
d.start = base['response']['start'].to_s.to_i
|
49
|
-
d.total = base['response']['numFound'].to_s.to_i
|
50
6
|
end
|
51
7
|
|
52
8
|
def docs
|
data/lib/rsolr-ext.rb
CHANGED
@@ -37,6 +37,14 @@ module RSolr
|
|
37
37
|
connection
|
38
38
|
end
|
39
39
|
|
40
|
+
# c = RSolr::Ext.connect
|
41
|
+
# c.find(:q=>'*:*').docs.size
|
42
|
+
def self.direct_connect(*args)
|
43
|
+
connection = RSolr.direct_connect(*args)
|
44
|
+
connection.extend RSolr::Ext::Connection
|
45
|
+
connection
|
46
|
+
end
|
47
|
+
|
40
48
|
end
|
41
49
|
|
42
50
|
end
|
data/rsolr-ext.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rsolr-ext"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "2009-11-
|
3
|
+
s.version = "0.10.0"
|
4
|
+
s.date = "2009-11-13"
|
5
5
|
|
6
6
|
s.summary = "An extension lib for RSolr"
|
7
7
|
s.email = "goodieboy@gmail.com"
|
@@ -34,6 +34,6 @@ Gem::Specification.new do |s|
|
|
34
34
|
|
35
35
|
s.extra_rdoc_files = %w(LICENSE README.rdoc)
|
36
36
|
|
37
|
-
s.add_dependency("
|
37
|
+
s.add_dependency("rsolr", ["=0.10.0"])
|
38
38
|
|
39
39
|
end
|
data/test/connection_test.rb
CHANGED
@@ -18,7 +18,7 @@ class RSolrExtConnectionTest < Test::Unit::TestCase
|
|
18
18
|
test 'the #find method with a custom request handler' do
|
19
19
|
connection = RSolr::Ext.connect
|
20
20
|
response = connection.find '/select', :q=>'*:*'
|
21
|
-
assert response.
|
21
|
+
assert response.raw[:path]=~/\/select/
|
22
22
|
end
|
23
23
|
|
24
24
|
test 'the response' do
|
data/test/request_test.rb
CHANGED
@@ -5,8 +5,8 @@ class RSolrExtRequestTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
test 'standard request' do
|
7
7
|
solr_params = RSolr::Ext::Request.map(
|
8
|
-
:
|
9
|
-
:
|
8
|
+
:start=>10,
|
9
|
+
:rows=>10,
|
10
10
|
:phrases=>{:name=>'This is a phrase'},
|
11
11
|
:filters=>['test', {:price=>(1..10)}],
|
12
12
|
:phrase_filters=>{:manu=>['Apple']},
|
data/test/response_test.rb
CHANGED
@@ -18,8 +18,6 @@ class RSolrExtResponseTest < Test::Unit::TestCase
|
|
18
18
|
assert r.ok?
|
19
19
|
assert_equal 11, r.docs.size
|
20
20
|
assert_equal 'EXPLICIT', r.params[:echoParams]
|
21
|
-
assert_equal 1, r.docs.previous_page
|
22
|
-
assert_equal 2, r.docs.next_page
|
23
21
|
#
|
24
22
|
assert r.kind_of?(RSolr::Ext::Response::Docs)
|
25
23
|
assert r.kind_of?(RSolr::Ext::Response::Facets)
|
@@ -73,33 +71,4 @@ class RSolrExtResponseTest < Test::Unit::TestCase
|
|
73
71
|
assert_equal 'cat', facet.name
|
74
72
|
end
|
75
73
|
|
76
|
-
=begin
|
77
|
-
|
78
|
-
# pagination for facets has been commented out in the response/facets module.
|
79
|
-
# ...need to think more about how this can be handled
|
80
|
-
|
81
|
-
test 'response::standard facets.paginate' do
|
82
|
-
raw_response = eval(mock_query_response)
|
83
|
-
raw_response['responseHeader']['params']['facet.offset'] = 1
|
84
|
-
raw_response['responseHeader']['params']['facet.limit'] = 2
|
85
|
-
|
86
|
-
r = RSolr::Ext::Response::Standard.new(raw_response)
|
87
|
-
|
88
|
-
assert_equal 2, r.facets.current_page
|
89
|
-
|
90
|
-
# always 1 less than facet.limit
|
91
|
-
assert_equal 1, r.facets.per_page
|
92
|
-
|
93
|
-
assert_equal 3, r.facets.next_page
|
94
|
-
|
95
|
-
assert_equal 1, r.facets.previous_page
|
96
|
-
|
97
|
-
# can't know how many pages there are with facets.... so we set it to -1
|
98
|
-
assert_equal -1, r.facets.total_pages
|
99
|
-
|
100
|
-
assert r.facets.has_next?
|
101
|
-
assert r.facets.has_previous?
|
102
|
-
end
|
103
|
-
=end
|
104
|
-
|
105
74
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsolr-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Mitchell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -18,9 +18,9 @@ dependencies:
|
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- - "
|
21
|
+
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.
|
23
|
+
version: 0.10.0
|
24
24
|
version:
|
25
25
|
description: An extension lib for RSolr
|
26
26
|
email: goodieboy@gmail.com
|