mwmitchell-rsolr_ext 0.0.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/LICENSE +13 -0
- data/README.rdoc +2 -0
- data/lib/rsolr_ext.rb +10 -0
- data/test/rsolr_ext_standard_test.rb +80 -0
- data/test/rsolr_ext_test.rb +26 -0
- data/test/test_unit_test_case.rb +18 -0
- metadata +63 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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.
|
data/README.rdoc
ADDED
data/lib/rsolr_ext.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'test_unit_test_case'
|
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr_ext')
|
|
3
|
+
|
|
4
|
+
class RSolrExtTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
test 'the :per_page and :page params from the Request::Select::Standard mapper' do
|
|
7
|
+
|
|
8
|
+
select_params = RSolrExt::Request::Select::Standard.new
|
|
9
|
+
select_params[:page] = 1
|
|
10
|
+
select_params[:per_page] = 10
|
|
11
|
+
|
|
12
|
+
# convert to solr params
|
|
13
|
+
params = select_params.to_solr
|
|
14
|
+
|
|
15
|
+
# make sure the non-solr keys have been removed
|
|
16
|
+
assert_nil params[:per_page]
|
|
17
|
+
assert_nil params[:page]
|
|
18
|
+
|
|
19
|
+
# rows and start should now be mapped correctly
|
|
20
|
+
assert_equal 10, params[:rows]
|
|
21
|
+
assert_equal 0, params[:start]
|
|
22
|
+
|
|
23
|
+
# the :rows and :start keys should be the only keys
|
|
24
|
+
assert_equal 2, params.keys.size
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test 'the :q and :phrases params from the Request::Select::Standard mapper' do
|
|
28
|
+
select_params = RSolrExt::Request::Select::Standard.new
|
|
29
|
+
select_params[:q] = 'mp3'
|
|
30
|
+
select_params[:phrases] = {:manu=>'Apple'}
|
|
31
|
+
|
|
32
|
+
params = select_params.to_solr
|
|
33
|
+
|
|
34
|
+
assert_nil params[:phrases]
|
|
35
|
+
|
|
36
|
+
assert_equal 'mp3 manu:"Apple"', params[:q]
|
|
37
|
+
|
|
38
|
+
assert_equal 1, params.keys.size
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'the :fq and :filters params from the Request::Select::Standard mapper' do
|
|
42
|
+
select_params = RSolrExt::Request::Select::Standard.new
|
|
43
|
+
select_params[:fq] = 'price:[50 TO 200]'
|
|
44
|
+
select_params[:filters] = {:manu=>'Apple'}
|
|
45
|
+
|
|
46
|
+
params = select_params.to_solr
|
|
47
|
+
|
|
48
|
+
assert_nil params[:filters]
|
|
49
|
+
|
|
50
|
+
assert_equal 'price:[50 TO 200] manu:Apple', params[:fq]
|
|
51
|
+
|
|
52
|
+
assert_equal 1, params.keys.size
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
test 'the :fq, :filters and :filter_phrases params from the Request::Select::Standard mapper' do
|
|
56
|
+
select_params = RSolrExt::Request::Select::Standard.new
|
|
57
|
+
select_params[:fq] = 'price:[50 TO 200]'
|
|
58
|
+
select_params[:filters] = {:manu=>'Apple'}
|
|
59
|
+
select_params[:phrase_filters] = {:name=>'iPod'}
|
|
60
|
+
|
|
61
|
+
params = select_params.to_solr
|
|
62
|
+
|
|
63
|
+
assert_nil params[:filters]
|
|
64
|
+
assert_nil params[:phrase_filters]
|
|
65
|
+
|
|
66
|
+
assert_equal 'price:[50 TO 200] manu:Apple name:"iPod"', params[:fq]
|
|
67
|
+
|
|
68
|
+
assert_equal 1, params.keys.size
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
test 'the :facets param from the Request::Select::Standard mapper' do
|
|
72
|
+
select_params = RSolrExt::Request::Select::Standard.new
|
|
73
|
+
select_params[:facets] = {
|
|
74
|
+
:queries => 'price:[50 TO 200]',
|
|
75
|
+
:fields=>['manu', 'price_range']
|
|
76
|
+
}
|
|
77
|
+
params = select_params.to_solr
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require 'test_unit_test_case'
|
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr_ext')
|
|
3
|
+
|
|
4
|
+
class RSolrExtTest < Test::Unit::TestCase
|
|
5
|
+
|
|
6
|
+
H = Object.new
|
|
7
|
+
H.extend RSolrExt::Helpers
|
|
8
|
+
|
|
9
|
+
test 'prep_value' do
|
|
10
|
+
value = 'the man'
|
|
11
|
+
assert_equal 'the man', H.prep_value(value, false)
|
|
12
|
+
assert_equal "\"the man\"", H.prep_value(value, true)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test 'build_query' do
|
|
16
|
+
assert_equal 'testing', H.build_query('testing')
|
|
17
|
+
assert_equal '"testing"', H.build_query('testing', :quote=>true)
|
|
18
|
+
assert_equal 'testing again', H.build_query(['testing', 'again'])
|
|
19
|
+
assert_equal '"testing" "again"', H.build_query(['testing', 'again'], :quote=>true)
|
|
20
|
+
assert_equal 'name:whatever', H.build_query({:name=>'whatever'})
|
|
21
|
+
assert_equal 'name:"whatever"', H.build_query({:name=>'whatever'}, :quote=>true)
|
|
22
|
+
assert_equal 'sam name:whatever i am', H.build_query(['sam', {:name=>'whatever'}, 'i', 'am'])
|
|
23
|
+
assert_equal 'testing AND blah', H.build_query(['testing', 'blah'], :join=>' AND ')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
class Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
def self.test(name, &block)
|
|
6
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
|
7
|
+
defined = instance_method(test_name) rescue false
|
|
8
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
|
9
|
+
if block_given?
|
|
10
|
+
define_method(test_name, &block)
|
|
11
|
+
else
|
|
12
|
+
define_method(test_name) do
|
|
13
|
+
flunk "No implementation provided for #{name}"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mwmitchell-rsolr_ext
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.5
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Matt Mitchell
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-03-11 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description: An extension lib for RSolr
|
|
17
|
+
email: goodieboy@gmail.com
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- LICENSE
|
|
24
|
+
- README.rdoc
|
|
25
|
+
files:
|
|
26
|
+
- lib/rsolr_ext.rb
|
|
27
|
+
- lib/rsolr_ext/helpers
|
|
28
|
+
- lib/rsolr_ext/request
|
|
29
|
+
- lib/rsolr_ext/response
|
|
30
|
+
- lib/rsolr_ext/to_solrable
|
|
31
|
+
- LICENSE
|
|
32
|
+
- README.rdoc
|
|
33
|
+
- rsolr_params.gemspec
|
|
34
|
+
has_rdoc: true
|
|
35
|
+
homepage: http://github.com/mwmitchell/rsolr_ext
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
|
|
39
|
+
require_paths:
|
|
40
|
+
- lib
|
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
version:
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: "0"
|
|
52
|
+
version:
|
|
53
|
+
requirements: []
|
|
54
|
+
|
|
55
|
+
rubyforge_project:
|
|
56
|
+
rubygems_version: 1.2.0
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 2
|
|
59
|
+
summary: An extension lib for RSolr
|
|
60
|
+
test_files:
|
|
61
|
+
- test/rsolr_ext_standard_test.rb
|
|
62
|
+
- test/rsolr_ext_test.rb
|
|
63
|
+
- test/test_unit_test_case.rb
|