Sha256: 8f0cfa17f4dda047938544c2d52a3aa50ceed2fccca1f813067d5cd8b0490431

Contents?: true

Size: 576 Bytes

Versions: 4

Compression:

Stored size: 576 Bytes

Contents

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

  attr_accessor :index, :words, :options

  def initialize(index, words, options = {})
    @index, @words = index, words
    @options = DefaultOptions.merge(options)
  end

  def excerpt!(text)
    connection.query(Riddle::Query.snippets(text, index, words, options)).
      first['snippet']
  end

  private

  def connection
    @connection ||= ThinkingSphinx::Connection.new
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thinking-sphinx-3.0.2 lib/thinking_sphinx/excerpter.rb
thinking-sphinx-3.0.1 lib/thinking_sphinx/excerpter.rb
thinking-sphinx-3.0.0 lib/thinking_sphinx/excerpter.rb
thinking-sphinx-3.0.0.rc lib/thinking_sphinx/excerpter.rb