mwmitchell-rsolr-ext 0.7.3 → 0.7.4
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/lib/rsolr-ext.rb +1 -1
- data/lib/rsolr-ext/doc.rb +7 -2
- data/lib/rsolr-ext/response/spelling.rb +65 -0
- data/rsolr-ext.gemspec +6 -2
- metadata +5 -3
data/lib/rsolr-ext.rb
CHANGED
data/lib/rsolr-ext/doc.rb
CHANGED
@@ -63,16 +63,21 @@ module RSolr::Ext::Doc
|
|
63
63
|
def self.included(base)
|
64
64
|
base.extend Callbacks
|
65
65
|
base.extend Findable
|
66
|
+
base.send :include, RSolr::Ext::Response::Docs::Accessible
|
66
67
|
end
|
67
68
|
|
68
69
|
# The original object passed in to the #new method
|
69
70
|
attr :_source_hash
|
70
71
|
|
72
|
+
# The original object passed, converted to a mash
|
73
|
+
attr :_source_mash
|
74
|
+
|
71
75
|
# Constructor **for the class that is getting this module included**
|
72
76
|
# source_doc should be a hash or something similar
|
73
77
|
# calls each of after_initialize blocks
|
74
78
|
def initialize(source_doc={})
|
75
79
|
@_source_hash = source_doc
|
80
|
+
@_source_mash = source_doc.to_mash
|
76
81
|
self.class.hooks.each do |h|
|
77
82
|
instance_eval &h
|
78
83
|
end
|
@@ -80,14 +85,14 @@ module RSolr::Ext::Doc
|
|
80
85
|
|
81
86
|
# for easy access to the solr id (route helpers etc..)
|
82
87
|
def id
|
83
|
-
@
|
88
|
+
@_source_mash['id']
|
84
89
|
end
|
85
90
|
|
86
91
|
# the wrapper method to the @_source_hash object.
|
87
92
|
# If a method is missing, it gets sent to @_source_hash
|
88
93
|
# with all of the original params and block
|
89
94
|
def method_missing(m, *args, &b)
|
90
|
-
@
|
95
|
+
@_source_mash.send(m, *args, &b)
|
91
96
|
end
|
92
97
|
|
93
98
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# A mixin for making access to the spellcheck component data easy.
|
2
|
+
#
|
3
|
+
# response.spelling.words
|
4
|
+
#
|
5
|
+
module RSolr::Ext::Response::Spelling
|
6
|
+
|
7
|
+
def spelling
|
8
|
+
@spelling ||= Base.new(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Base
|
12
|
+
|
13
|
+
attr :response
|
14
|
+
|
15
|
+
def initialize(response)
|
16
|
+
@response = response
|
17
|
+
end
|
18
|
+
|
19
|
+
# returns an array of spelling suggestion for specific query words,
|
20
|
+
# as provided in the solr response. Only includes words with higher
|
21
|
+
# frequency of occurrence than word in original query.
|
22
|
+
# can't do a full query suggestion because we only get info for each word;
|
23
|
+
# combination of words may not have results.
|
24
|
+
# Thanks to Naomi Dushay!
|
25
|
+
def words
|
26
|
+
@words ||= (
|
27
|
+
word_suggestions = []
|
28
|
+
spellcheck = self.response[:spellcheck]
|
29
|
+
if spellcheck && spellcheck[:suggestions]
|
30
|
+
suggestions = spellcheck[:suggestions]
|
31
|
+
unless suggestions.nil?
|
32
|
+
# suggestions is an array:
|
33
|
+
# (query term)
|
34
|
+
# (hash of term info and term suggestion)
|
35
|
+
# ...
|
36
|
+
# (query term)
|
37
|
+
# (hash of term info and term suggestion)
|
38
|
+
# 'correctlySpelled'
|
39
|
+
# true/false
|
40
|
+
# collation
|
41
|
+
# (suggestion for collation)
|
42
|
+
i_stop = suggestions.index("correctlySpelled")
|
43
|
+
# step through array in 2s to get info for each term
|
44
|
+
0.step(i_stop-1, 2) do |i|
|
45
|
+
term = suggestions[i]
|
46
|
+
term_info = suggestions[i+1]
|
47
|
+
# term_info is a hash:
|
48
|
+
# numFound =>
|
49
|
+
# startOffset =>
|
50
|
+
# endOffset =>
|
51
|
+
# origFreq =>
|
52
|
+
# suggestion => { frequency =>, word => }
|
53
|
+
origFreq = term_info['origFreq']
|
54
|
+
suggFreq = term_info['suggestion']['frequency']
|
55
|
+
word_suggestions << term_info['suggestion']['word'] if suggFreq > origFreq
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
word_suggestions.uniq
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/rsolr-ext.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rsolr-ext"
|
3
|
-
s.version = "0.7.
|
4
|
-
s.date = "2009-
|
3
|
+
s.version = "0.7.4"
|
4
|
+
s.date = "2009-07-31"
|
5
5
|
s.summary = "An extension lib for RSolr"
|
6
6
|
s.email = "goodieboy@gmail.com"
|
7
7
|
s.homepage = "http://github.com/mwmitchell/rsolr_ext"
|
@@ -23,6 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
|
24
24
|
"lib/rsolr-ext/response/docs.rb",
|
25
25
|
"lib/rsolr-ext/response/facets.rb",
|
26
|
+
"lib/rsolr-ext/response/spelling.rb",
|
27
|
+
|
26
28
|
"lib/rsolr-ext/response.rb",
|
27
29
|
|
28
30
|
"lib/rsolr-ext.rb",
|
@@ -38,5 +40,7 @@ Gem::Specification.new do |s|
|
|
38
40
|
'test/test_unit_test_case.rb',
|
39
41
|
'test/helper.rb'
|
40
42
|
]
|
43
|
+
|
41
44
|
s.extra_rdoc_files = %w(LICENSE README.rdoc)
|
45
|
+
|
42
46
|
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.7.
|
4
|
+
version: 0.7.4
|
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-
|
12
|
+
date: 2009-07-31 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/rsolr-ext/request.rb
|
32
32
|
- lib/rsolr-ext/response/docs.rb
|
33
33
|
- lib/rsolr-ext/response/facets.rb
|
34
|
+
- lib/rsolr-ext/response/spelling.rb
|
34
35
|
- lib/rsolr-ext/response.rb
|
35
36
|
- lib/rsolr-ext.rb
|
36
37
|
- LICENSE
|
@@ -38,6 +39,7 @@ files:
|
|
38
39
|
- rsolr-ext.gemspec
|
39
40
|
has_rdoc: true
|
40
41
|
homepage: http://github.com/mwmitchell/rsolr_ext
|
42
|
+
licenses:
|
41
43
|
post_install_message:
|
42
44
|
rdoc_options: []
|
43
45
|
|
@@ -58,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
60
|
requirements: []
|
59
61
|
|
60
62
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
63
|
+
rubygems_version: 1.3.5
|
62
64
|
signing_key:
|
63
65
|
specification_version: 2
|
64
66
|
summary: An extension lib for RSolr
|