class ThinkingSphinx::Excerpter

Constants

DefaultOptions

Attributes

index[RW]
options[RW]
words[RW]

Public Class Methods

new(index, words, options = {}) click to toggle source
# File lib/thinking_sphinx/excerpter.rb, line 12
def initialize(index, words, options = {})
  @index, @words = index, words
  @options = DefaultOptions.merge(options)
  @words = @options.delete(:words) if @options[:words]
end

Public Instance Methods

excerpt!(text) click to toggle source
# File lib/thinking_sphinx/excerpter.rb, line 18
def excerpt!(text)
  result = ThinkingSphinx::Connection.take do |connection|
    query = statement_for text
    ThinkingSphinx::Logger.log :query, query do
      connection.execute(query).first['snippet']
    end
  end

  encoded? ? result : ThinkingSphinx::UTF8.encode(result)
end

Private Instance Methods

encoded?() click to toggle source
# File lib/thinking_sphinx/excerpter.rb, line 35
def encoded?
  ThinkingSphinx::Configuration.instance.settings['utf8'].nil? ||
  ThinkingSphinx::Configuration.instance.settings['utf8']
end
statement_for(text) click to toggle source
# File lib/thinking_sphinx/excerpter.rb, line 31
def statement_for(text)
  Riddle::Query.snippets(text, index, words, options)
end