delsolr 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -90,13 +90,28 @@ module DelSolr
90
90
  # solr is super-weird about the way it returns suggestions,
91
91
  # hence this strangeness:
92
92
  # 'spellcheck'=>{'suggestions'=>['fishh',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['fish']},'collation','fish']}
93
- def collation
94
- @collation ||= begin
95
- collation = nil
96
- suggestions.in_groups_of(2) {|k,v| collation = v if k == 'collation'} if suggestions
97
- collation
93
+ def collation_with_correction
94
+ @collation_with_correction ||= begin
95
+ collation, correction = nil, {}
96
+ if suggestions
97
+ (suggestions.length/2).times do |i|
98
+ k = suggestions[i*2]
99
+ v = suggestions[i*2+1]
100
+ collation = v if k == 'collation'
101
+ correction[k] = v['suggestion'][0] if v.is_a?(Hash)
102
+ end
103
+ end
104
+ {'collation' => collation, 'correction' => correction}
98
105
  end
99
106
  end
107
+
108
+ def correction
109
+ collation_with_correction['correction']
110
+ end
111
+
112
+ def collation
113
+ collation_with_correction['collation']
114
+ end
100
115
 
101
116
  # Returns the query time in ms
102
117
  def qtime
@@ -92,7 +92,11 @@ class ResponseTest < Test::Unit::TestCase
92
92
  '9_widget'=>{},
93
93
  '10_widget'=>{},
94
94
  '11_widget'=>{},
95
- '12_widget'=>{}}}
95
+ '12_widget'=>{}},
96
+ 'spellcheck'=>{
97
+ 'suggestions'=>[
98
+ 'fishh',{'numFound'=>1,'startOffset'=>0,'endOffset'=>4,'suggestion'=>['fish']},
99
+ 'collation','fish']}}
96
100
  }
97
101
 
98
102
  def test_001
@@ -128,4 +132,14 @@ class ResponseTest < Test::Unit::TestCase
128
132
  assert(!r.respond_to?(:scores))
129
133
  end
130
134
 
135
+ def test_spellcheck
136
+ r = nil
137
+ qb = DelSolr::Client::QueryBuilder.new('standard', :query => {:index_type => 'widget'}, :facets => {:query => 'city_idm:19596', :prefix => {:key => 19596}} )
138
+ qb.request_string # need to generate this...
139
+ assert_nothing_raised { r = DelSolr::Client::Response.new(@@test_001, qb) }
140
+
141
+ assert_equal('fish', r.collation)
142
+ assert_equal('fish', r.correction['fishh'])
143
+ end
144
+
131
145
  end
metadata CHANGED
@@ -1,38 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: delsolr
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.6
4
5
  prerelease:
5
- version: 0.1.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ben VandenBos
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2009-11-02 00:00:00 -08:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2009-11-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: mocha
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2171652600 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
24
21
  version: 0.9.0
25
22
  type: :development
26
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: *2171652600
27
25
  description: Ruby wrapper for Lucene Solr
28
26
  email:
29
27
  executables: []
30
-
31
28
  extensions: []
32
-
33
29
  extra_rdoc_files: []
34
-
35
- files:
30
+ files:
36
31
  - License.txt
37
32
  - README.txt
38
33
  - lib/delsolr.rb
@@ -45,35 +40,32 @@ files:
45
40
  - test/test_helper.rb
46
41
  - test/test_query_builder.rb
47
42
  - test/test_response.rb
48
- has_rdoc: true
49
43
  homepage: http://github.com/avvo/delsolr
50
44
  licenses: []
51
-
52
45
  post_install_message:
53
46
  rdoc_options: []
54
-
55
- require_paths:
47
+ require_paths:
56
48
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
58
50
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
56
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
69
61
  requirements: []
70
-
71
62
  rubyforge_project:
72
- rubygems_version: 1.5.0
63
+ rubygems_version: 1.8.5
73
64
  signing_key:
74
65
  specification_version: 3
75
- summary: DelSolr is a light weight ruby wrapper for solr. It's intention is to expose the full power of solr queries while keeping the interface as ruby-esque as possible.
76
- test_files:
66
+ summary: DelSolr is a light weight ruby wrapper for solr. It's intention is to expose
67
+ the full power of solr queries while keeping the interface as ruby-esque as possible.
68
+ test_files:
77
69
  - test/test_client.rb
78
70
  - test/test_helper.rb
79
71
  - test/test_query_builder.rb