Sha256: 34649135b511b7cef66abe2e08091ec64dbd8870c2936a904b08fc3987f8cd29

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

require File.join(File.dirname(__FILE__), 'spec_helper')

describe 'function query' do
  it "should send query to solr with boost function" do
    session.search Post do
      keywords('pizza') do
        boost(function { :average_rating })
      end
    end
    connection.should have_last_search_including(:bf, 'average_rating_ft')
  end

  it "should handle boost function with constant float" do
    session.search Post do
      keywords('pizza') do
        boost(function { 10.5 })
      end
    end
    connection.should have_last_search_including(:bf, '10.5')
  end

  it "should handle boost function with time literal" do
    session.search Post do
      keywords('pizza') do
        boost(function { Time.parse('2010-03-25 14:13:00 EDT') })
      end
    end
    connection.should have_last_search_including(:bf, '2010-03-25T18:13:00Z')
  end
 
  it "should handle arbitrary functions in a function query block" do
    session.search Post do
      keywords('pizza') do
        boost(function { product(:average_rating, 10) })
      end
    end
    connection.should have_last_search_including(:bf, 'product(average_rating_ft,10)')
  end
 
  it "should handle nested functions in a function query block" do
    session.search Post do
      keywords('pizza') do
        boost(function { product(:average_rating, sum(:average_rating, 20)) })
      end
    end
    connection.should have_last_search_including(:bf, 'product(average_rating_ft,sum(average_rating_ft,20))')
  end

  # TODO SOLR 1.5
  it "should raise ArgumentError if string literal passed" do
    lambda do
      session.search Post do
        keywords('pizza') do
          boost(function { "hello world" })
        end
      end
    end.should raise_error(ArgumentError)
  end

  it "should raise UnrecognizedFieldError if bogus field name passed" do
    lambda do
      session.search Post do
        keywords('pizza') do
          boost(function { :bogus })
        end
      end
    end.should raise_error(Sunspot::UnrecognizedFieldError)
  end
end

Version data entries

9 entries across 9 versions & 4 rubygems

Version Path
erichummel-sunspot-1.2.1g spec/api/query/function_spec.rb
erichummel-sunspot-1.2.1f spec/api/query/function_spec.rb
erichummel-sunspot-1.2.1b spec/api/query/function_spec.rb
erichummel-sunspot-1.2.1a spec/api/query/function_spec.rb
lisausa-sunspot-1.2.1.1 spec/api/query/function_spec.rb
sunspot-1.2.1 spec/api/query/function_spec.rb
sunspot-1.2.0 spec/api/query/function_spec.rb
nuatt_sunspot-1.1.0.3 spec/api/query/function_spec.rb
sunspot-1.1.0 spec/api/query/function_spec.rb