class Sunspot::Search::AbstractSearch

Attributes

solr_result[RW]

Public Instance Methods

spellcheck_results() click to toggle source
# File lib/sunspot_suggest/sunspot/search/abstract_search.rb, line 107
def spellcheck_results
  @spellcheck_results = begin
    spellcheck = Spellcheck.new

    raw_suggestions.each_slice(2) do |k, v|
      if k == 'collation'
        spellcheck.add_collation(v)
      elsif k == 'correctlySpelled'
        spellcheck.correctly_spelled = (v == 'true')
      else
        spellcheck.add_suggestion(k, v)
      end
    end
    spellcheck
  end
end
suggested() click to toggle source
# File lib/sunspot_suggest/sunspot/search/abstract_search.rb, line 90
def suggested
  raw = raw_suggestions
  return nil unless raw.is_a?(Array)

  s = SuggestedResult.new
  Hash[*raw].each do |k, v|
    if k == 'correctlySpelled'
      s.correctly_spelled = v
    else
      s.query = k
      s.suggestions = v['suggestion']
    end
  end
  s
end

Private Instance Methods

raw_suggestions() click to toggle source
# File lib/sunspot_suggest/sunspot/search/abstract_search.rb, line 126
def raw_suggestions
  ["spellcheck", "suggestions"].inject(@solr_result) {|h, k| h && h[k]} || []
end