Sha256: 0b0c709ea16fdeb562b32439b0da97eee6a3b541c1acf65ec25957e07d1af048

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 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_boosted('average_rating_ft', 'pizza')
  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_boosted('10.5', 'pizza')
  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_boosted('2010-03-25T18:13:00Z', 'pizza')
  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_boosted('product(average_rating_ft,10)', 'pizza')
  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_boosted('product(average_rating_ft,sum(average_rating_ft,20))', 'pizza')
  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

5 entries across 5 versions & 1 rubygems

Version Path
ruben-sunspot-1.1.4 spec/api/query/function_spec.rb
ruben-sunspot-1.1.3 spec/api/query/function_spec.rb
ruben-sunspot-1.1.2 spec/api/query/function_spec.rb
ruben-sunspot-1.1.1 spec/api/query/function_spec.rb
ruben-sunspot-1.1.0 spec/api/query/function_spec.rb