Sha256: b3e7a1c1569ba287ab1726c0088d59feafa1e794fb8943ac5b13d5f78261817e

Contents?: true

Size: 878 Bytes

Versions: 8

Compression:

Stored size: 878 Bytes

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))

describe 'keyword highlighting' do
  before :all do
    @posts = []
    @posts << Post.new(:body => 'And the fox laughed')
    @posts << Post.new(:body => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit', :blog_id => 1)
    Sunspot.index!(*@posts)
    @search_result = Sunspot.search(Post) { keywords 'fox', :highlight => true }
  end
  
  it 'should include highlights in the results' do
    @search_result.hits.first.highlights.length.should == 1
  end
  
  it 'should return formatted highlight fragments' do
    @search_result.hits.first.highlights(:body).first.format.should == 'And the <em>fox</em> laughed'
  end
  
  it 'should be empty for non-keyword searches' do
    search_result = Sunspot.search(Post){ with :blog_id, 1 }
    search_result.hits.first.highlights.should be_empty
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
sunspot-1.3.3 spec/integration/highlighting_spec.rb
sunspot-1.3.2 spec/integration/highlighting_spec.rb
sunspot-1.3.1 spec/integration/highlighting_spec.rb
cb_sunspot-2.0.0.pre.5 spec/integration/highlighting_spec.rb
cb_sunspot-2.0.0.pre.3 spec/integration/highlighting_spec.rb
cb_sunspot-2.0.0.pre3 spec/integration/highlighting_spec.rb
sunspot-1.3.0 spec/integration/highlighting_spec.rb
sunspot-1.3.0.rc6 spec/integration/highlighting_spec.rb