Class: ThinkingSphinx::Excerpter

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

Constant Summary collapse

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.



12
13
14
15
16
# 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

Instance Attribute Details

#indexObject

Returns the value of attribute index.



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

def index
  @index
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#wordsObject

Returns the value of attribute words.



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

def words
  @words
end

Instance Method Details

#excerpt!(text) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# 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