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

- (Excerpter) initialize(index, words, options = {})



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

- (Object) index

Returns the value of attribute index



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

def index
  @index
end

- (Object) options

Returns the value of attribute options



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

def options
  @options
end

- (Object) words

Returns the value of attribute words



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

def words
  @words
end

Instance Method Details

- (Object) excerpt!(text)



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

def excerpt!(text)
  result = connection.query(statement_for(text)).first['snippet']

  result.encode!("ISO-8859-1")
  result.force_encoding("UTF-8")
end