Class: ThinkingSphinx::Excerpter

Inherits:
Object
  • Object
show all
Defined in:
lib/thinking_sphinx/excerpter.rb

Constant Summary

DefaultOptions =
{
  :before_match    => '<span class="match">',
  :after_match     => '</span>',
  :chunk_separator => ' &#8230; ' # ellipsis
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index, words, options = {}) ⇒ Excerpter

Returns a new instance of Excerpter



10
11
12
13
14
# File 'lib/thinking_sphinx/excerpter.rb', line 10

def initialize(index, words, options = {})
  @index, @words = index, words
  @options = DefaultOptions.merge(options)
  @words = @options.delete(:words) if @options[:words]
end

Instance Attribute Details

#indexObject

Returns the value of attribute index



8
9
10
# File 'lib/thinking_sphinx/excerpter.rb', line 8

def index
  @index
end

#optionsObject

Returns the value of attribute options



8
9
10
# File 'lib/thinking_sphinx/excerpter.rb', line 8

def options
  @options
end

#wordsObject

Returns the value of attribute words



8
9
10
# File 'lib/thinking_sphinx/excerpter.rb', line 8

def words
  @words
end

Instance Method Details

#excerpt!(text) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/thinking_sphinx/excerpter.rb', line 16

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