Sha256: a5fdcd10d28054eadebd3ae290049aca95a9b7697a793fba1ef3eb5319a5ac3c

Contents?: true

Size: 1.3 KB

Versions: 37

Compression:

Stored size: 1.3 KB

Contents

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

describe 'more_like_this' do
  before :all do
    Sunspot.remove_all
    @posts = [
      Post.new(:body => "one two three", :tags => %w(ruby sunspot rsolr)),
      Post.new(:body => "four five six", :tags => %w(ruby solr lucene)),
      Post.new(:body => "two three four", :tags => %w(python sqlalchemy)),
      Post.new(:body => "three four five", :tags => %w(ruby sunspot mat)),
      Post.new(:body => "six seven eight", :tags => %w(bogus airplane))
    ]
    Sunspot.index!(@posts)
  end

  it 'should return results for all MLT fields' do
    Sunspot.more_like_this(@posts.first).results.to_set.should == @posts[1..3].to_set
  end

  it 'should return results for specified text field' do
    Sunspot.more_like_this(@posts.first) do 
      fields :body
    end.results.to_set.should == @posts[2..3].to_set
  end

  it 'should return empty result set if no results' do
    Sunspot.more_like_this(@posts.last) do
      with(:title, 'bogus')
    end.results.should == []
  end

  describe 'when non-indexed object searched' do
    before(:each) { @mlt = Sunspot.more_like_this(Post.new) }

    it 'should return empty result set' do
      @mlt.results.should == []
    end

    it 'shoult return a total of 0' do
      @mlt.total.should == 0
    end
  end
end

Version data entries

37 entries across 37 versions & 7 rubygems

Version Path
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/sunspot-2.2.7/spec/integration/more_like_this_spec.rb
sunspot-2.2.7 spec/integration/more_like_this_spec.rb
sunspot-2.2.6 spec/integration/more_like_this_spec.rb
sunspot-2.2.5 spec/integration/more_like_this_spec.rb
sunspot-2.2.4 spec/integration/more_like_this_spec.rb
sunspot-2.2.3 spec/integration/more_like_this_spec.rb
sunspot-2.2.2 spec/integration/more_like_this_spec.rb
sunspot-2.2.1 spec/integration/more_like_this_spec.rb
sunspot-2.2.0 spec/integration/more_like_this_spec.rb
sunspot-2.1.1 spec/integration/more_like_this_spec.rb
sunspot-2.1.0 spec/integration/more_like_this_spec.rb
sunspot-2.0.0 spec/integration/more_like_this_spec.rb
sunspot-2.0.0.pre.130115 spec/integration/more_like_this_spec.rb
gojee-sunspot-2.0.5 spec/integration/more_like_this_spec.rb
sunspot-2.0.0.pre.120925 spec/integration/more_like_this_spec.rb
sunspot_solr-2.0.0.pre.120924 sunspot/spec/integration/more_like_this_spec.rb
sunspot_rails-2.0.0.pre.120924 sunspot/spec/integration/more_like_this_spec.rb
sunspot-2.0.0.pre.120924 sunspot/spec/integration/more_like_this_spec.rb
gojee-sunspot-2.0.4 spec/integration/more_like_this_spec.rb
gojee-sunspot-2.0.2 spec/integration/more_like_this_spec.rb