Sha256: 51676b69f4fc0591b234479ccaa4e745d08d7ac8d185ceca1ec54b9ee2c813b1

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

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)
    @posts << Post.new(:body => 'Lorem ipsum dolor sit amet', :title => '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
  
  it "should process multiple keyword request on different fields with highlights correctly" do
    search_results = nil
    expect do
      search_results = Sunspot.search(Post) do
        keywords 'Lorem ipsum', :fields => [:body] do
          highlight :body
        end
        keywords 'consectetur', :fields => [:title] do
          highlight :title
        end
      end
    end.to_not raise_error
    search_results.results.length.should eq(1)
    search_results.results.first.should eq(@posts.last)
    # this one might be a Solr bug, therefore not related to Sunspot itself
    # search_results.hits.first.highlights.should_not be_empty
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/spec/integration/highlighting_spec.rb
sunspot-2.2.7 spec/integration/highlighting_spec.rb
sunspot-2.2.6 spec/integration/highlighting_spec.rb
sunspot-2.2.5 spec/integration/highlighting_spec.rb
sunspot-2.2.4 spec/integration/highlighting_spec.rb
sunspot-2.2.3 spec/integration/highlighting_spec.rb
sunspot-2.2.2 spec/integration/highlighting_spec.rb
sunspot-2.2.1 spec/integration/highlighting_spec.rb
sunspot-2.2.0 spec/integration/highlighting_spec.rb
sunspot-2.1.1 spec/integration/highlighting_spec.rb