Class: ThinkingSphinx::Excerpter
- Inherits:
-
Object
- Object
- ThinkingSphinx::Excerpter
- Defined in:
- lib/thinking_sphinx/excerpter.rb
Constant Summary collapse
- DefaultOptions =
{ :before_match => '<span class="match">', :after_match => '</span>', :chunk_separator => ' … ' # ellipsis }
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#options ⇒ Object
Returns the value of attribute options.
-
#words ⇒ Object
Returns the value of attribute words.
Instance Method Summary collapse
- #excerpt!(text) ⇒ Object
-
#initialize(index, words, options = {}) ⇒ Excerpter
constructor
A new instance of Excerpter.
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, = {}) @index, @words = index, words @options = DefaultOptions.merge() @words = @options.delete(:words) if @options[:words] end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
10 11 12 |
# File 'lib/thinking_sphinx/excerpter.rb', line 10 def index @index end |
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/thinking_sphinx/excerpter.rb', line 10 def @options end |
#words ⇒ Object
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 |