Class: RSolr::Ext::Response::Spelling::Base
- Inherits:
-
Object
- Object
- RSolr::Ext::Response::Spelling::Base
- Defined in:
- lib/rsolr-ext/response/spelling.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response) ⇒ Base
constructor
A new instance of Base.
-
#words ⇒ Object
returns an array of spelling suggestion for specific query words, as provided in the solr response.
Constructor Details
#initialize(response) ⇒ Base
Returns a new instance of Base.
15 16 17 |
# File 'lib/rsolr-ext/response/spelling.rb', line 15 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
13 14 15 |
# File 'lib/rsolr-ext/response/spelling.rb', line 13 def response @response end |
Instance Method Details
#words ⇒ Object
returns an array of spelling suggestion for specific query words, as provided in the solr response. Only includes words with higher frequency of occurrence than word in original query. can’t do a full query suggestion because we only get info for each word;
combination of words may not have results. Thanks to Naomi Dushay!
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rsolr-ext/response/spelling.rb', line 25 def words @words ||= ( word_suggestions = [] spellcheck = self.response[:spellcheck] if spellcheck && spellcheck[:suggestions] suggestions = spellcheck[:suggestions] unless suggestions.nil? # suggestions is an array: # (query term) # (hash of term info and term suggestion) # ... # (query term) # (hash of term info and term suggestion) # 'correctlySpelled' # true/false # collation # (suggestion for collation) i_stop = suggestions.index("correctlySpelled") # step through array in 2s to get info for each term 0.step(i_stop-1, 2) do |i| term = suggestions[i] term_info = suggestions[i+1] # term_info is a hash: # numFound => # startOffset => # endOffset => # origFreq => # suggestion => { frequency =>, word => } origFreq = term_info['origFreq'] suggFreq = term_info['suggestion']['frequency'] word_suggestions << term_info['suggestion']['word'] if suggFreq > origFreq end end end word_suggestions.uniq ) end |