mwmitchell-rsolr_ext 0.0.5 → 0.1.0

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/README.rdoc CHANGED
@@ -1,2 +1,22 @@
1
1
  =RSolrExt
2
- A set of helper methods/modules to assist in building Solr queries and handling responses for RSolr.
2
+ A set of helper methods/modules to assist in building Solr queries and handling responses for RSolr.
3
+
4
+ ==Examples
5
+
6
+ ===Params
7
+ params = RSolrExt::Params.create_fielded_queries(:name=>'a string...', :cat=>[:one, :two])
8
+ params == ['name:"a string..."', 'cat:"one"', 'cat:"two"']
9
+
10
+ The params hash can then be passed into RSolr for fielded querying.
11
+
12
+ ===Select
13
+ solr_hash = {} # an evaluated solr (ruby) hash
14
+ response = RSolrExt::Response::Select.create(solr_hash)
15
+ response.docs.each do |d|
16
+ puts d[:cat]
17
+ end
18
+ puts response.facets.inspect
19
+
20
+ ====Pagination
21
+ In your view (using will_paginate):
22
+ <%= will_paginate(response) %>
data/lib/rsolr_ext.rb CHANGED
@@ -1,10 +1,21 @@
1
+ # add this directory to the load path if it hasn't already been added
2
+ lambda {|base|
3
+ $: << base unless $:.include?(base) || $:.include?(File.expand_path(base))
4
+ }.call(File.dirname(__FILE__))
5
+
6
+ unless defined?(Mash)
7
+ require 'mash'
8
+ end
9
+
10
+ unless Hash.respond_to?(:to_mash)
11
+ require 'core_ext'
12
+ end
13
+
1
14
  module RSolrExt
2
15
 
3
- autoload :Helpers, 'rsolr_ext/helpers.rb'
4
- autoload :ToSolrable, 'rsolr_ext/to_solrable.rb'
16
+ VERSION = '0.1.0'
17
+
18
+ autoload :Params, 'rsolr_ext/params'
5
19
  autoload :Response, 'rsolr_ext/response'
6
- autoload :Request, 'rsolr_ext/request'
7
20
 
8
- end # end RSolrExt
9
-
10
- include RSolrExt::Request::Select
21
+ end # end RSolrExt
data/rsolr_ext.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rsolr_ext"
3
+ s.version = "0.1.0"
4
+ s.date = "2009-03-12"
5
+ s.summary = "An extension lib for RSolr"
6
+ s.email = "goodieboy@gmail.com"
7
+ s.homepage = "http://github.com/mwmitchell/rsolr_ext"
8
+ s.description = "An extension lib for RSolr"
9
+ s.has_rdoc = true
10
+ s.authors = ["Matt Mitchell"]
11
+ s.files = [
12
+ "lib/rsolr_ext.rb",
13
+ "lib/rsolr_ext/params",
14
+ "lib/rsolr_ext/response",
15
+ "lib/rsolr_ext/response/base",
16
+ "lib/rsolr_ext/response/luke",
17
+ "lib/rsolr_ext/response/select",
18
+ "lib/rsolr_ext/response/update",
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "rsolr_ext.gemspec"
22
+ ]
23
+ s.test_files = ['test/rsolr_ext_standard_test.rb', 'test/rsolr_ext_test.rb', 'test/test_unit_test_case.rb']
24
+ s.extra_rdoc_files = %w(LICENSE README.rdoc)
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-rsolr_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.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-03-11 00:00:00 -07:00
12
+ date: 2009-03-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,13 +24,15 @@ extra_rdoc_files:
24
24
  - README.rdoc
25
25
  files:
26
26
  - lib/rsolr_ext.rb
27
- - lib/rsolr_ext/helpers
28
- - lib/rsolr_ext/request
27
+ - lib/rsolr_ext/params
29
28
  - lib/rsolr_ext/response
30
- - lib/rsolr_ext/to_solrable
29
+ - lib/rsolr_ext/response/base
30
+ - lib/rsolr_ext/response/luke
31
+ - lib/rsolr_ext/response/select
32
+ - lib/rsolr_ext/response/update
31
33
  - LICENSE
32
34
  - README.rdoc
33
- - rsolr_params.gemspec
35
+ - rsolr_ext.gemspec
34
36
  has_rdoc: true
35
37
  homepage: http://github.com/mwmitchell/rsolr_ext
36
38
  post_install_message:
@@ -1,80 +0,0 @@
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
@@ -1,26 +0,0 @@
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