mwmitchell-rsolr-ext 0.5.0 → 0.5.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/lib/rsolr-ext.rb +2 -1
- data/lib/rsolr-ext/request.rb +45 -77
- data/rsolr-ext.gemspec +1 -1
- data/test/request_test.rb +4 -1
- metadata +1 -1
- data/lib/rsolr-ext/request/dismax.rb +0 -3
- data/lib/rsolr-ext/request/standard.rb +0 -38
data/lib/rsolr-ext.rb
CHANGED
@@ -15,11 +15,12 @@ module RSolr
|
|
15
15
|
|
16
16
|
module Ext
|
17
17
|
|
18
|
-
VERSION = '0.5.
|
18
|
+
VERSION = '0.5.1'
|
19
19
|
|
20
20
|
autoload :Request, 'rsolr-ext/request.rb'
|
21
21
|
autoload :Response, 'rsolr-ext/response.rb'
|
22
22
|
autoload :HashMethodizer, 'rsolr-ext/hash_methodizer.rb'
|
23
|
+
autoload :Mapable, 'rsolr-ext/mapable.rb'
|
23
24
|
|
24
25
|
end
|
25
26
|
|
data/lib/rsolr-ext/request.rb
CHANGED
@@ -1,91 +1,59 @@
|
|
1
1
|
module RSolr::Ext::Request
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
# be processed. Each key name can match a key in the input hash.
|
7
|
-
# If there is a match, a method by the name of "map_#{key}" is
|
8
|
-
# called with the following args: input[key], output_hash
|
9
|
-
# The method is responsible for processing the value.
|
10
|
-
# The return value from the method does nothing.
|
11
|
-
#
|
12
|
-
# For example: if the mapped params list has a name, :query,
|
13
|
-
# there should be a method like: map_query(input_value, output_hash)
|
14
|
-
module Mapable
|
3
|
+
autoload :Queryable, 'rsolr-ext/request/queryable.rb'
|
4
|
+
|
5
|
+
class Standard
|
15
6
|
|
16
|
-
|
17
|
-
|
18
|
-
# runs through all of the keys in MAPPED_PARAMS.
|
19
|
-
# calls any mapper methods that match the current key in MAPPED_PARAMS.
|
20
|
-
# The mapped keys from the input hash are deleted.
|
21
|
-
# returns a new hash.
|
22
|
-
def map(input)
|
23
|
-
result = input.dup
|
24
|
-
self.class::MAPPED_PARAMS.each do |meth|
|
25
|
-
input_value = result.delete(meth)
|
26
|
-
next if input_value.to_s.empty?
|
27
|
-
send("map_#{meth}", input_value, result)
|
28
|
-
end
|
29
|
-
result
|
30
|
-
end
|
7
|
+
include RSolr::Ext::Mapable
|
8
|
+
include RSolr::Ext::Request::Queryable
|
31
9
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
10
|
+
MAPPED_PARAMS = [
|
11
|
+
:per_page,
|
12
|
+
:page,
|
13
|
+
:phrases, # quoted q param
|
14
|
+
:filters, # fq params
|
15
|
+
:phrase_filters, # quoted fq params,
|
16
|
+
:facets
|
17
|
+
]
|
18
|
+
|
19
|
+
def map_per_page(value,output)
|
20
|
+
output[:rows] = value.to_i
|
42
21
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
# Wraps a string around double quotes
|
50
|
-
def quote(value)
|
51
|
-
%("#{value}")
|
22
|
+
|
23
|
+
def map_page(value,output)
|
24
|
+
raise ':per_page must be set when using :page' unless output[:rows]
|
25
|
+
page = value.to_s.to_i-1
|
26
|
+
page = page < 1 ? 0 : page
|
27
|
+
output[:start] = page * output[:rows]
|
52
28
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
29
|
+
|
30
|
+
def map_phrases(value,output)
|
31
|
+
output[:q] = append_to_param(output[:q], build_query(value, true))
|
32
|
+
end
|
33
|
+
|
34
|
+
def map_filters(value,output)
|
35
|
+
output[:fq] = append_to_param(output[:fq], build_query(value))
|
36
|
+
end
|
37
|
+
|
38
|
+
def map_phrase_filters(value,output)
|
39
|
+
output[:fq] = append_to_param(output[:fq], build_query(value, true))
|
57
40
|
end
|
58
41
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# passed back into build_query (recursive)
|
68
|
-
def build_query(value, quote_string=false)
|
69
|
-
case value
|
70
|
-
when String,Symbol
|
71
|
-
return quote_string ? quote(value.to_s) : value.to_s
|
72
|
-
when Array
|
73
|
-
value.collect do |v|
|
74
|
-
build_query(v, quote_string)
|
75
|
-
end.flatten
|
76
|
-
when Hash
|
77
|
-
return value.collect do |(k,v)|
|
78
|
-
if v.is_a?(Range)
|
79
|
-
"#{k}:#{build_range(v)}"
|
80
|
-
else
|
81
|
-
"#{k}:#{build_query(v, quote_string)}"
|
82
|
-
end
|
83
|
-
end.flatten
|
42
|
+
def map_facets(value,output)
|
43
|
+
output[:facet] = true
|
44
|
+
if value[:fields]
|
45
|
+
fields = value[:fields].is_a?(Array) ? value[:fields] : [value[:fields]]
|
46
|
+
fields.each do |f|
|
47
|
+
output['facet.field'] ||= []
|
48
|
+
output['facet.field'] << f
|
49
|
+
end
|
84
50
|
end
|
85
51
|
end
|
52
|
+
|
86
53
|
end
|
87
54
|
|
88
|
-
|
89
|
-
|
55
|
+
class Dismax < Standard
|
56
|
+
|
57
|
+
end
|
90
58
|
|
91
59
|
end
|
data/rsolr-ext.gemspec
CHANGED
data/test/request_test.rb
CHANGED
@@ -11,12 +11,15 @@ class RSolrExtRequestTest < Test::Unit::TestCase
|
|
11
11
|
:phrases=>{:name=>'This is a phrase'},
|
12
12
|
:filters=>['test', {:price=>(1..10)}],
|
13
13
|
:phrase_filters=>{:manu=>['Apple']},
|
14
|
-
:q=>'ipod'
|
14
|
+
:q=>'ipod',
|
15
|
+
:facets=>{:fields=>['cat', 'blah']}
|
15
16
|
)
|
16
17
|
assert_equal "test price:[1 TO 10] manu:\"Apple\"", solr_params[:fq]
|
17
18
|
assert_equal 10, solr_params[:start]
|
18
19
|
assert_equal 10, solr_params[:rows]
|
19
20
|
assert_equal "ipod name:\"This is a phrase\"", solr_params[:q]
|
21
|
+
assert_equal ['cat', 'blah'], solr_params['facet.field']
|
22
|
+
assert_equal true, solr_params[:facet]
|
20
23
|
end
|
21
24
|
|
22
25
|
end
|
metadata
CHANGED
@@ -1,38 +0,0 @@
|
|
1
|
-
class RSolr::Ext::Request::Standard
|
2
|
-
|
3
|
-
include RSolr::Ext::Request::Mapable
|
4
|
-
include RSolr::Ext::Request::Queryable
|
5
|
-
|
6
|
-
MAPPED_PARAMS = [
|
7
|
-
:per_page,
|
8
|
-
:page,
|
9
|
-
:phrases, # quoted q param
|
10
|
-
:filters, # fq params
|
11
|
-
:phrase_filters # quoted fq params
|
12
|
-
]
|
13
|
-
|
14
|
-
def map_per_page(value,output)
|
15
|
-
output[:rows] = value.to_i
|
16
|
-
end
|
17
|
-
|
18
|
-
def map_page(value,output)
|
19
|
-
raise ':per_page must be set when using :page' unless output[:rows]
|
20
|
-
page = value.to_s.to_i-1
|
21
|
-
page = page < 1 ? 0 : page
|
22
|
-
output[:start] = page * output[:rows]
|
23
|
-
end
|
24
|
-
|
25
|
-
def map_phrases(value,output)
|
26
|
-
output[:q] = append_to_param(output[:q], build_query(value, true))
|
27
|
-
end
|
28
|
-
|
29
|
-
def map_filters(value,output)
|
30
|
-
output[:fq] = append_to_param(output[:fq], build_query(value))
|
31
|
-
end
|
32
|
-
|
33
|
-
def map_phrase_filters(value,output)
|
34
|
-
output[:fq] = append_to_param(output[:fq], build_query(value, true))
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
end
|