mwmitchell-rsolr 0.5.8 → 0.5.9

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 CHANGED
@@ -1,3 +1,11 @@
1
+ 0.5.9 - January 7, 2009
2
+ Finally brought in the ExtLib Mash classes for incoming params and response hashes from solr
3
+ - this gives the ability to access/set values for hashes using strings OR symbols (HashWithIndifferentAccess)
4
+ Organized response tests
5
+ Added more response tests
6
+ Simplified the RSolr::Response::Base class by supporting only raw/string ruby input
7
+ Added method to Response::IndexInfo for grabbing a Solr field list
8
+
1
9
  0.5.7 - January 5, 2009
2
10
  Changed name from Solr to RSolr, changed all references to Solr to RSolr
3
11
  Added new tests for RSolr::Mapper and RSolr::Message
@@ -1,5 +1,7 @@
1
1
  module RSolr::Connection::SearchExt
2
2
 
3
+ # TODO : clean this thing up dude
4
+
3
5
  def search(params={})
4
6
  params = params.to_mash
5
7
  if params[:fields]
@@ -12,14 +14,19 @@ module RSolr::Connection::SearchExt
12
14
  phrase_filters = params.delete(:phrase_filters)
13
15
  params[:filters] ||= {}
14
16
  phrase_filters.each do |filter,values|
17
+ values = [values] unless values.is_a?(Array)
15
18
  params[:filters][filter] ||= []
19
+ params[:filters][filter] = [params[:filters][filter]] unless params[:filters][filter].is_a?(Array)
16
20
  values.each do |v|
17
- params[:filters][filter] << "\"#{v}\""
21
+ params[:filters][filter] << %(\"#{v}\")
18
22
  end
19
23
  end
20
24
  end
21
25
 
22
- params[:fq] = build_filters(params.delete(:filters)) if params[:filters]
26
+ if params[:filters]
27
+ filter_params = params.delete(:filters)
28
+ params[:fq] = build_filters(filter_params)
29
+ end
23
30
  facets = params.delete(:facets) if params[:facets]
24
31
 
25
32
  if facets
@@ -20,4 +20,14 @@ class RSolr::Response::IndexInfo < RSolr::Response::Base
20
20
  @version = @index[:version]
21
21
  end
22
22
 
23
+ # Returns an array of fields from the index
24
+ # An optional rule can be used for "grepping" field names:
25
+ # field_list(/_facet$/)
26
+ def field_list(rule=nil)
27
+ @data[:fields].select do |k,v|
28
+ rule ? k =~ rule : true
29
+ end.collect{|k,v|k}
30
+ end
31
+
32
+
23
33
  end
data/lib/rsolr.rb CHANGED
@@ -7,7 +7,7 @@ proc {|base, files|
7
7
 
8
8
  module RSolr
9
9
 
10
- VERSION = '0.5.8'
10
+ VERSION = '0.5.9'
11
11
 
12
12
  autoload :Message, 'rsolr/message'
13
13
  autoload :Response, 'rsolr/response'
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
+
3
+ class ResponseBaseTest < RSolrBaseTest
4
+
5
+ def test_accessors
6
+
7
+ adapter_response = {:body=>mock_query_response}
8
+
9
+ r = RSolr::Response::Base.new(adapter_response)
10
+
11
+ assert_class Mash, r.data
12
+ assert_class Mash, r.params
13
+ assert_class Mash, r.header
14
+
15
+ # make sure the incoming adapter response is the same as the response.input
16
+ assert_equal adapter_response, r.input
17
+
18
+ assert_equal r.query_time, r.header[:QTime]
19
+ assert_equal r.query_time, r.header['QTime']
20
+
21
+ assert_equal r.params, r.header[:params]
22
+ assert_equal r.params, r.header['params']
23
+
24
+ assert_equal '*:*', r.params[:q]
25
+ assert_equal '*:*', r.params['q']
26
+
27
+ assert_equal 0, r.status
28
+ assert_equal r.status, r.header[:status]
29
+ assert_equal r.status, r.header['status']
30
+
31
+ assert_equal r.header, r.data[:responseHeader]
32
+ assert_equal r.header, r.data['responseHeader']
33
+
34
+ assert r.ok?
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
+
3
+ class ResponsePaginationTest < RSolrBaseTest
4
+
5
+ def create_response(params={})
6
+ response = RSolr::Response::Query::Base.new(mock_query_response)
7
+ response.params.merge! params
8
+ response
9
+ end
10
+
11
+ # test the Solr::Connection pagination methods
12
+ def test_connection_calculate_start
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)
17
+ end
18
+
19
+ def test_connection_modify_params_for_pagination
20
+ dummy_connection = RSolr::Connection::Base.new(nil)
21
+ p = dummy_connection.send(:modify_params_for_pagination, {:page=>1})
22
+ assert_equal 0, p[:start]
23
+ assert_equal 10, p[:rows]
24
+ #
25
+ p = dummy_connection.send(:modify_params_for_pagination, {:page=>10, :per_page=>100})
26
+ assert_equal 900, p[:start]
27
+ assert_equal 100, p[:rows]
28
+ end
29
+
30
+ def test_math
31
+ response = create_response({'rows'=>5})
32
+ assert_equal response.params['rows'], response.per_page
33
+ assert_equal 26, response.total
34
+ assert_equal 1, response.current_page
35
+ assert_equal 6, response.total_pages
36
+
37
+ # now switch the rows (per_page)
38
+ # total and current page should remain the same value
39
+ # page_count should change
40
+
41
+ response = create_response({'rows'=>2})
42
+ assert_equal response.params['rows'], response.per_page
43
+ assert_equal 26, response.total
44
+ assert_equal 1, response.current_page
45
+ assert_equal 13, response.total_pages
46
+
47
+ # now switch the start
48
+
49
+ response = create_response({'rows'=>3})
50
+ response.instance_variable_set '@start', 4
51
+ assert_equal response.params['rows'], response.per_page
52
+ assert_equal 26, response.total
53
+ # 2 per page, currently on the 10th item
54
+ assert_equal 2, response.current_page
55
+ assert_equal 9, response.total_pages
56
+ end
57
+
58
+ end
@@ -0,0 +1,44 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
+
3
+ class ResponseQueryTest < RSolrBaseTest
4
+
5
+ def query_response
6
+ RSolr::Response::Query::Base.new(mock_query_response)
7
+ end
8
+
9
+ def test_accessors
10
+ r = query_response
11
+ assert r.response
12
+ assert_class Array, r.docs
13
+
14
+ # total and num_found are the same
15
+ assert_equal 26, r.num_found
16
+ assert_equal r.total, r.num_found
17
+
18
+ # start and offset are the same
19
+ assert_equal 0, r.start
20
+ assert_equal r.offset, r.start
21
+ end
22
+
23
+ # make sure the docs respond to key and symbol access (using the Mash class)
24
+ def test_doc_string_and_symbol_key_access
25
+ response = query_response
26
+ response.docs.each do |doc|
27
+ assert doc.is_a?(Mash)
28
+ assert_equal doc['id'], doc[:id]
29
+ assert doc.key?(:id)
30
+ assert doc.key?('id')
31
+ if doc[:cat]
32
+ # if this doc has a cat (multiValues) of memory and electronics
33
+ # test the has? method
34
+ if doc[:cat].include?('memory') and doc[:cat].include?('electronics')
35
+ assert doc.has?(:cat, 'memory')
36
+ assert doc.has?(:cat, /elec/)
37
+ assert doc.has?('cat', 'memory')
38
+ assert doc.has?('cat', /elec/)
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,19 @@
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
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.5.8
4
+ version: 0.5.9
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: 2008-12-30 00:00:00 -08:00
12
+ date: 2009-01-07 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -93,7 +93,6 @@ test_files:
93
93
  - test/connection/direct_test.rb
94
94
  - test/connection/http_test.rb
95
95
  - test/connection/test_methods.rb
96
- - test/connection/search_ext_test_methods.rb
97
96
  - test/core_ext_test
98
97
  - test/http_client/curb_test.rb
99
98
  - test/http_client/net_http_test.rb
@@ -102,7 +101,10 @@ test_files:
102
101
  - test/indexer.rb
103
102
  - test/mapper_test.rb
104
103
  - test/message_test.rb
105
- - test/pagination_test.rb
106
- - test/ruby-lang.org.rss.xml
104
+ - test/response/base_test.rb
105
+ - test/response/pagination_test.rb
106
+ - test/response/query_test.rb
107
+ - test/response/search_ext_test.rb
107
108
  - test/rsolr_test
109
+ - test/ruby-lang.org.rss.xml
108
110
  - test/test_helpers.rb