solr-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/lib/solr.rb +18 -0
  2. data/lib/solr/connection.rb +158 -0
  3. data/lib/solr/document.rb +71 -0
  4. data/lib/solr/exception.rb +13 -0
  5. data/lib/solr/field.rb +35 -0
  6. data/lib/solr/request.rb +24 -0
  7. data/lib/solr/request/add_document.rb +63 -0
  8. data/lib/solr/request/base.rb +29 -0
  9. data/lib/solr/request/commit.rb +21 -0
  10. data/lib/solr/request/delete.rb +50 -0
  11. data/lib/solr/request/dismax.rb +43 -0
  12. data/lib/solr/request/index_info.rb +17 -0
  13. data/lib/solr/request/optimize.rb +21 -0
  14. data/lib/solr/request/ping.rb +36 -0
  15. data/lib/solr/request/select.rb +54 -0
  16. data/lib/solr/request/standard.rb +105 -0
  17. data/lib/solr/request/update.rb +22 -0
  18. data/lib/solr/response.rb +24 -0
  19. data/lib/solr/response/add_document.rb +17 -0
  20. data/lib/solr/response/base.rb +42 -0
  21. data/lib/solr/response/commit.rb +32 -0
  22. data/lib/solr/response/delete.rb +13 -0
  23. data/lib/solr/response/dismax.rb +8 -0
  24. data/lib/solr/response/index_info.rb +26 -0
  25. data/lib/solr/response/optimize.rb +14 -0
  26. data/lib/solr/response/ping.rb +28 -0
  27. data/lib/solr/response/ruby.rb +42 -0
  28. data/lib/solr/response/standard.rb +60 -0
  29. data/lib/solr/response/xml.rb +37 -0
  30. data/lib/solr/xml.rb +47 -0
  31. data/test/unit/add_document_test.rb +40 -0
  32. data/test/unit/commit_test.rb +41 -0
  33. data/test/unit/connection_test.rb +55 -0
  34. data/test/unit/delete_test.rb +56 -0
  35. data/test/unit/dismax_request_test.rb +26 -0
  36. data/test/unit/document_test.rb +59 -0
  37. data/test/unit/field_test.rb +42 -0
  38. data/test/unit/ping_test.rb +51 -0
  39. data/test/unit/request_test.rb +61 -0
  40. data/test/unit/response_test.rb +42 -0
  41. data/test/unit/solr_mock_base.rb +40 -0
  42. data/test/unit/standard_request_test.rb +108 -0
  43. data/test/unit/standard_response_test.rb +174 -0
  44. data/test/unit/suite.rb +25 -0
  45. metadata +92 -0
@@ -0,0 +1,26 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+
16
+ class DismaxRequestTest < Test::Unit::TestCase
17
+
18
+ def test_basic_query
19
+ request = Solr::Request::Dismax.new(:query => 'query', :phrase_slop => '1000', :sort => [{:deedle => :descending}])
20
+ assert_match(/q=query/, request.to_s)
21
+ assert_match(/qt=dismax/, request.to_s)
22
+ assert_match(/ps=1000/, request.to_s)
23
+ assert_match(/sort=deedle%20desc/, request.to_s)
24
+ end
25
+
26
+ end
@@ -0,0 +1,59 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+
16
+ class DocumentTest < Test::Unit::TestCase
17
+
18
+ def test_xml
19
+ doc = Solr::Document.new
20
+ doc << Solr::Field.new(:creator => 'Erik Hatcher')
21
+ assert_kind_of Solr::XML::Element, doc.to_xml
22
+ assert_match(/<doc>[\s]*<field name=['"]creator['"]>Erik Hatcher<\/field>[\s]*<\/doc>/m, doc.to_xml.to_s)
23
+ end
24
+
25
+ def test_repeatable
26
+ doc = Solr::Document.new
27
+ doc << Solr::Field.new(:creator => 'Erik Hatcher')
28
+ doc << Solr::Field.new(:creator => 'Otis Gospodnetic')
29
+ assert_kind_of Solr::XML::Element, doc.to_xml
30
+ assert_match(/<doc>[\s]*<field name=['"]creator['"]>Erik Hatcher<\/field>[\s]*<field name=['"]creator['"]>Otis Gospodnetic<\/field>[\s]*<\/doc>/m, doc.to_xml.to_s)
31
+ end
32
+
33
+ def test_repeatable_in_hash
34
+ doc = Solr::Document.new({:creator => ['Erik Hatcher', 'Otis Gospodnetic']})
35
+ assert_match(/<doc>[\s]*<field name=['"]creator['"]>Erik Hatcher<\/field>[\s]*<field name=['"]creator['"]>Otis Gospodnetic<\/field>[\s]*<\/doc>/m, doc.to_xml.to_s)
36
+ end
37
+
38
+ def test_bad_doc
39
+ doc = Solr::Document.new
40
+ assert_raise(RuntimeError) do
41
+ doc << "invalid"
42
+ end
43
+ end
44
+
45
+ def test_hash_shorthand
46
+ doc = Solr::Document.new :creator => 'Erik Hatcher', :title => 'Lucene in Action'
47
+ assert_equal 'Erik Hatcher', doc[:creator]
48
+ assert_equal 'Lucene in Action', doc[:title]
49
+ assert_equal nil, doc[:foo]
50
+
51
+ doc = Solr::Document.new
52
+ doc << {:creator => 'Erik Hatcher', :title => 'Lucene in Action'}
53
+ doc[:subject] = 'Search'
54
+ assert_equal 'Erik Hatcher', doc[:creator]
55
+ assert_equal 'Lucene in Action', doc[:title]
56
+ assert_equal 'Search', doc[:subject]
57
+ end
58
+
59
+ end
@@ -0,0 +1,42 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+
16
+ class FieldTest < Test::Unit::TestCase
17
+
18
+ def test_xml
19
+ field = Solr::Field.new :creator => 'Erik Hatcher'
20
+ assert_kind_of Solr::XML::Element, field.to_xml
21
+ assert_match(/<field name=["']creator["']>Erik Hatcher<\/field>/, field.to_xml.to_s)
22
+ end
23
+
24
+ def test_escaped_xml
25
+ field = Solr::Field.new :creator => 'Erik Hatcher & His Amazing Leaping Ability'
26
+ assert_kind_of Solr::XML::Element, field.to_xml
27
+ assert_match(/<field name=["']creator["']>Erik Hatcher &amp; His Amazing Leaping Ability<\/field>/, field.to_xml.to_s)
28
+ end
29
+
30
+ def test_xml_date
31
+ field = Solr::Field.new :time => Time.now
32
+ assert_kind_of Solr::XML::Element, field.to_xml
33
+ assert_match(/<field name=["']time["']>[\d]{4}-[\d]{2}-[\d]{2}T[\d]{2}:[\d]{2}:[\d]{2}Z<\/field>/, field.to_xml.to_s)
34
+ end
35
+
36
+ def test_i18n_xml
37
+ field = Solr::Field.new :i18nstring => 'Äêâîôû Öëäïöü'
38
+ assert_kind_of Solr::XML::Element, field.to_xml
39
+ assert_match(/<field name=["']i18nstring["']>Äêâîôû Öëäïöü<\/field>/m, field.to_xml.to_s)
40
+ end
41
+
42
+ end
@@ -0,0 +1,51 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'solr_mock_base'
14
+
15
+ class PingTest < SolrMockBaseTestCase
16
+
17
+ def test_ping_response
18
+ xml =
19
+ <<PING_RESPONSE
20
+
21
+ <?xml-stylesheet type="text/xsl" href="ping.xsl"?>
22
+
23
+ <solr>
24
+ <ping>
25
+
26
+ </ping>
27
+ </solr>
28
+ PING_RESPONSE
29
+ conn = Solr::Connection.new('http://localhost:9999')
30
+ set_post_return(xml)
31
+ response = conn.send(Solr::Request::Ping.new)
32
+ assert_kind_of Solr::Response::Ping, response
33
+ assert_equal true, response.ok?
34
+
35
+ # test shorthand
36
+ assert true, conn.ping
37
+ end
38
+
39
+ def test_bad_ping_response
40
+ xml = "<foo>bar</foo>"
41
+ conn = Solr::Connection.new('http://localhost:9999')
42
+ set_post_return(xml)
43
+ response = conn.send(Solr::Request::Ping.new)
44
+ assert_kind_of Solr::Response::Ping, response
45
+ assert_equal false, response.ok?
46
+
47
+ # test shorthand
48
+ assert_equal false, conn.ping
49
+ end
50
+
51
+ end
@@ -0,0 +1,61 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+
16
+ class BadRequest < Solr::Request::Base
17
+ end
18
+
19
+ class RequestTest < Test::Unit::TestCase
20
+
21
+ def test_commit_request
22
+ request = Solr::Request::Commit.new
23
+ assert_equal :xml, request.response_format
24
+ assert_equal 'update', request.handler
25
+ assert_equal '<commit/>', request.to_s
26
+ end
27
+
28
+ def test_add_doc_request
29
+ request = Solr::Request::AddDocument.new(:title => "title")
30
+ assert_match(/<add>[\s]*<doc>[\s]*<field name=["']title["']>title<\/field>[\s]*<\/doc>[\s]*<\/add>/m, request.to_s)
31
+ assert_equal :xml, request.response_format
32
+ assert_equal 'update', request.handler
33
+
34
+ assert_raise(RuntimeError) do
35
+ Solr::Request::AddDocument.new("invalid")
36
+ end
37
+ end
38
+
39
+ def test_add_multidoc_request
40
+ request = Solr::Request::AddDocument.new([{:title => "title1"}, {:title => "title2"}])
41
+ assert_match(/<add>[\s]*<doc>[\s]*<field name=["']title["']>title1<\/field>[\s]*<\/doc>[\s]*<doc>[\s]*<field name=["']title["']>title2<\/field>[\s]*<\/doc>[\s]*<\/add>/m, request.to_s)
42
+ assert_equal :xml, request.response_format
43
+ assert_equal 'update', request.handler
44
+ end
45
+
46
+ def test_ping_request
47
+ request = Solr::Request::Ping.new
48
+ assert_equal :xml, request.response_format
49
+ end
50
+
51
+ def test_bad_request_class
52
+ assert_raise(RuntimeError) do
53
+ BadRequest.new.response_format
54
+ end
55
+
56
+ assert_raise(RuntimeError) do
57
+ BadRequest.new.handler
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,42 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+ require 'solr_mock_base'
16
+
17
+
18
+ class ResponseTest < SolrMockBaseTestCase
19
+
20
+ def test_response_xml_error
21
+ begin
22
+ Solr::Response::Xml.new("<broken>invalid xml&")
23
+ flunk("failed to get Solr::Exception as expected")
24
+ rescue Exception => exception
25
+ assert_kind_of Solr::Exception, exception
26
+ assert_match 'invalid response xml', exception.to_s
27
+ end
28
+ end
29
+
30
+ def test_invalid_ruby
31
+ assert_raise(Solr::Exception) do
32
+ Solr::Response::Ruby.new(' {...')
33
+ end
34
+ end
35
+
36
+ def test_bogus_request_handling
37
+ assert_raise(Solr::Exception) do
38
+ Solr::Response::Base.make_response(Solr::Request::Select.new, "response data")
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,40 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+
16
+ # TODO: Maybe replace this with flexmock
17
+ class SolrMockBaseTestCase < Test::Unit::TestCase
18
+ include Solr
19
+
20
+ def setup
21
+ Connection.send(:alias_method, :orig_post, :post)
22
+ end
23
+
24
+ def teardown
25
+ Connection.send(:alias_method, :post, :orig_post)
26
+ end
27
+
28
+ def set_post_return(value)
29
+ Connection.class_eval %{
30
+ def post(request)
31
+ %q{#{value}}
32
+ end
33
+ }
34
+ end
35
+
36
+ def test_dummy
37
+ # So Test::Unit is happy running this class
38
+ end
39
+
40
+ end
@@ -0,0 +1,108 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'test/unit'
14
+ require 'solr'
15
+
16
+ class StandardRequestTest < Test::Unit::TestCase
17
+
18
+ def test_basic_query
19
+ request = Solr::Request::Standard.new(:query => 'query')
20
+ assert_equal :ruby, request.response_format
21
+ assert_equal 'select', request.handler
22
+ assert_equal 'query', request.to_hash[:q]
23
+ assert_match /q=query/, request.to_s
24
+ end
25
+
26
+ def test_bad_params
27
+ assert_raise(RuntimeError) do
28
+ Solr::Request::Standard.new(:foo => "invalid")
29
+ end
30
+
31
+ assert_raise(RuntimeError) do
32
+ Solr::Request::Standard.new(:query => "valid", :foo => "invalid")
33
+ end
34
+
35
+ assert_raise(RuntimeError) do
36
+ Solr::Request::Standard.new(:query => "valid", :operator => :bogus)
37
+ end
38
+ end
39
+
40
+ def test_common_params
41
+ request = Solr::Request::Standard.new(:query => 'query', :start => 10, :rows => 50,
42
+ :filter_queries => ['fq1', 'fq2'], :field_list => ['id','title','score'], :operator => :and)
43
+ assert_equal 10, request.to_hash[:start]
44
+ assert_equal 50, request.to_hash[:rows]
45
+ assert_equal ['fq1','fq2'], request.to_hash[:fq]
46
+ assert_equal "id,title,score", request.to_hash[:fl]
47
+ assert_equal "AND", request.to_hash["q.op"]
48
+ end
49
+
50
+ def test_missing_params
51
+ request = Solr::Request::Standard.new(:query => 'query', :debug_query => false, :facets => {:fields =>[:category_facet]})
52
+ assert_nil request.to_hash[:rows]
53
+ assert_no_match /rows/, request.to_s
54
+ assert_no_match /facet\.sort/, request.to_s
55
+ assert_match /debugQuery/, request.to_s
56
+ end
57
+
58
+ def test_facet_params_all
59
+ request = Solr::Request::Standard.new(:query => 'query',
60
+ :facets => {
61
+ :fields => [:genre,
62
+ # field that overrides the global facet parameters
63
+ {:year => {:limit => 50, :mincount => 0, :missing => false, :sort => :term, :prefix=>"199"}}],
64
+ :queries => ["q1", "q2"],
65
+ :prefix => "cat",
66
+ :limit => 5, :zeros => true, :mincount => 20, :sort => :count # global facet parameters
67
+ }
68
+ )
69
+
70
+ hash = request.to_hash
71
+ assert_equal true, hash[:facet]
72
+ assert_equal [:genre, :year], hash["facet.field"]
73
+ assert_equal ["q1", "q2"], hash["facet.query"]
74
+ assert_equal 5, hash["facet.limit"]
75
+ assert_equal 20, hash["facet.mincount"]
76
+ assert_equal true, hash["facet.sort"]
77
+ assert_equal "cat", hash["facet.prefix"]
78
+ assert_equal 50, hash["f.year.facet.limit"]
79
+ assert_equal 0, hash["f.year.facet.mincount"]
80
+ assert_equal false, hash["f.year.facet.sort"]
81
+ assert_equal "199", hash["f.year.facet.prefix"]
82
+ end
83
+
84
+ def test_basic_sort
85
+ request = Solr::Request::Standard.new(:query => 'query', :sort => [{:title => :descending}])
86
+ assert_equal 'query;title desc', request.to_hash[:q]
87
+ end
88
+
89
+ def test_highlighting
90
+ request = Solr::Request::Standard.new(:query => 'query',
91
+ :highlighting => {
92
+ :field_list => ['title', 'author'],
93
+ :max_snippets => 3,
94
+ :require_field_match => true,
95
+ :prefix => "<blink>",
96
+ :suffix => "</blink>"
97
+ }
98
+ )
99
+
100
+ hash = request.to_hash
101
+ assert_equal true, hash[:hl]
102
+ assert_equal "title,author", hash["hl.fl"]
103
+ assert_equal true, hash["hl.requireFieldMatch"]
104
+ assert_equal "<blink>", hash["hl.simple.pre"]
105
+ assert_equal "</blink>", hash["hl.simple.post"]
106
+ end
107
+
108
+ end
@@ -0,0 +1,174 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ require 'solr_mock_base'
14
+
15
+ class StandardResponseTest < SolrMockBaseTestCase
16
+
17
+ def test_basic
18
+ ruby_code =
19
+ <<RUBY_CODE
20
+ {
21
+ 'responseHeader'=>{
22
+ 'status'=>0,
23
+ 'QTime'=>1,
24
+ 'params'=>{
25
+ 'wt'=>'ruby',
26
+ 'rows'=>'10',
27
+ 'explainOther'=>'',
28
+ 'start'=>'0',
29
+ 'hl.fl'=>'',
30
+ 'indent'=>'on',
31
+ 'q'=>'guido',
32
+ 'fl'=>'*,score',
33
+ 'qt'=>'standard',
34
+ 'version'=>'2.2'}},
35
+ 'response'=>{'numFound'=>1,'start'=>0,'maxScore'=>0.67833745,'docs'=>[
36
+ {
37
+ 'name'=>'guido von rossum',
38
+ 'id'=>'123',
39
+ 'timestamp'=>'2007-01-16T09:55:30.589Z',
40
+ 'score'=>0.67833745}]
41
+ }}
42
+ RUBY_CODE
43
+ conn = Solr::Connection.new 'http://localhost:9999'
44
+ set_post_return(ruby_code)
45
+ response = conn.send(Solr::Request::Standard.new(:query => 'foo'))
46
+ assert_equal true, response.ok?
47
+ assert response.query_time
48
+ assert_equal 1, response.total_hits
49
+ assert_equal 0, response.start
50
+ assert_equal 0.67833745, response.max_score
51
+ assert_equal 1, response.hits.length
52
+ end
53
+
54
+ def test_iteration
55
+ ruby_code =
56
+ <<RUBY_CODE
57
+ {
58
+ 'responseHeader'=>{
59
+ 'status'=>0,
60
+ 'QTime'=>0,
61
+ 'params'=>{
62
+ 'wt'=>'ruby',
63
+ 'rows'=>'10',
64
+ 'explainOther'=>'',
65
+ 'start'=>'0',
66
+ 'hl.fl'=>'',
67
+ 'indent'=>'on',
68
+ 'q'=>'guido',
69
+ 'fl'=>'*,score',
70
+ 'qt'=>'standard',
71
+ 'version'=>'2.2'}},
72
+ 'response'=>{'numFound'=>22,'start'=>0,'maxScore'=>0.53799295,'docs'=>[
73
+ {
74
+ 'name'=>'guido von rossum the 0',
75
+ 'id'=>'0',
76
+ 'score'=>0.53799295},
77
+ {
78
+ 'name'=>'guido von rossum the 1',
79
+ 'id'=>'1',
80
+ 'score'=>0.53799295},
81
+ {
82
+ 'name'=>'guido von rossum the 2',
83
+ 'id'=>'2',
84
+ 'score'=>0.53799295},
85
+ {
86
+ 'name'=>'guido von rossum the 3',
87
+ 'id'=>'3',
88
+ 'score'=>0.53799295},
89
+ {
90
+ 'name'=>'guido von rossum the 4',
91
+ 'id'=>'4',
92
+ 'score'=>0.53799295},
93
+ {
94
+ 'name'=>'guido von rossum the 5',
95
+ 'id'=>'5',
96
+ 'score'=>0.53799295},
97
+ {
98
+ 'name'=>'guido von rossum the 6',
99
+ 'id'=>'6',
100
+ 'score'=>0.53799295},
101
+ {
102
+ 'name'=>'guido von rossum the 7',
103
+ 'id'=>'7',
104
+ 'score'=>0.53799295},
105
+ {
106
+ 'name'=>'guido von rossum the 8',
107
+ 'id'=>'8',
108
+ 'score'=>0.53799295},
109
+ {
110
+ 'name'=>'guido von rossum the 9',
111
+ 'id'=>'9',
112
+ 'score'=>0.53799295}]
113
+ }}
114
+ RUBY_CODE
115
+ conn = Solr::Connection.new 'http://localhost:9999'
116
+ set_post_return(ruby_code)
117
+
118
+ count = 0
119
+ conn.query('foo') do |hit|
120
+ assert_equal "guido von rossum the #{count}", hit['name']
121
+ count += 1
122
+ end
123
+
124
+ assert_equal 10, count
125
+ end
126
+
127
+ def test_facets
128
+ ruby_code =
129
+ <<RUBY_CODE
130
+ {
131
+ 'responseHeader'=>{
132
+ 'status'=>0,
133
+ 'QTime'=>1897,
134
+ 'params'=>{
135
+ 'facet.limit'=>'20',
136
+ 'wt'=>'ruby',
137
+ 'rows'=>'0',
138
+ 'facet'=>'true',
139
+ 'facet.mincount'=>'1',
140
+ 'facet.field'=>[
141
+ 'subject_genre_facet',
142
+ 'subject_geographic_facet',
143
+ 'subject_format_facet',
144
+ 'subject_era_facet',
145
+ 'subject_topic_facet'],
146
+ 'indent'=>'true',
147
+ 'fl'=>'*,score',
148
+ 'q'=>'[* TO *]',
149
+ 'qt'=>'standard',
150
+ 'facet.sort'=>'true'}},
151
+ 'response'=>{'numFound'=>49999,'start'=>0,'maxScore'=>1.0,'docs'=>[]
152
+ },
153
+ 'facet_counts'=>{
154
+ 'facet_queries'=>{},
155
+ 'facet_fields'=>{
156
+ 'subject_genre_facet'=>[
157
+ 'Biography.',2605,
158
+ 'Congresses.',1837,
159
+ 'Bibliography.',672,
160
+ 'Exhibitions.',642,
161
+ 'Periodicals.',615,
162
+ 'Sources.',485]}}
163
+ }
164
+ RUBY_CODE
165
+ set_post_return(ruby_code)
166
+ conn = Solr::Connection.new "http://localhost:9999"
167
+ response = conn.query('foo')
168
+ facets = response.field_facets('subject_genre_facet')
169
+ assert_equal 2605, facets[0].value
170
+ assert_equal 485, facets[5].value
171
+ end
172
+
173
+ end
174
+