|
| 1 | +require File.expand_path('../spec_helper', __FILE__) |
| 2 | + |
| 3 | +describe Soolr::Dismax do |
| 4 | + let(:headline) { Soolr::Field.new(:headline, Soolr::StringType) } |
| 5 | + let(:body) { Soolr::Field.new(:body, Soolr::StringType) } |
| 6 | + |
| 7 | + describe '#to_params' do |
| 8 | + it 'should have :q param' do |
| 9 | + params_from('pizza')[:q].should == 'pizza' |
| 10 | + end |
| 11 | + |
| 12 | + it 'should set :qt param to "dismax"' do |
| 13 | + params_from('pizza')[:qt].should == 'dismax' |
| 14 | + end |
| 15 | + |
| 16 | + it 'should set :qf param' do |
| 17 | + params_from('pizza') do |dismax| |
| 18 | + dismax.add_field(headline) |
| 19 | + end[:qf].should == 'headline' |
| 20 | + end |
| 21 | + |
| 22 | + it 'should set multiple fields in :qf param' do |
| 23 | + params_from('pizza') do |dismax| |
| 24 | + dismax.add_field(headline) |
| 25 | + dismax.add_field(body) |
| 26 | + end[:qf].should == 'headline body' |
| 27 | + end |
| 28 | + |
| 29 | + it 'should set boost in :qf param if given' do |
| 30 | + params_from('pizza') do |dismax| |
| 31 | + dismax.add_field(headline, :boost => 2.0) |
| 32 | + dismax.add_field(body) |
| 33 | + end[:qf].should == 'headline^2.0 body' |
| 34 | + end |
| 35 | + |
| 36 | + it 'should set minimum match' do |
| 37 | + params_from('pizza pasta pepperoni') do |dismax| |
| 38 | + dismax.minimum_match = 2 |
| 39 | + end[:mm].should == 2 |
| 40 | + end |
| 41 | + |
| 42 | + it 'should set phrase fields' do |
| 43 | + params_from('pizza') do |dismax| |
| 44 | + dismax.add_field(headline, :phrase_boost => 5.0) |
| 45 | + dismax.add_field(body, :phrase_boost => 2.0) |
| 46 | + end[:pf].should == 'headline^5.0 body^2.0' |
| 47 | + end |
| 48 | + |
| 49 | + it 'should set phrase slop' do |
| 50 | + params_from('pizza') do |dismax| |
| 51 | + dismax.phrase_slop = 2 |
| 52 | + end[:ps].should == 2 |
| 53 | + end |
| 54 | + |
| 55 | + it 'should set query phrase slop' do |
| 56 | + params_from('pizza') do |dismax| |
| 57 | + dismax.query_phrase_slop = 2 |
| 58 | + end[:qs].should == 2 |
| 59 | + end |
| 60 | + |
| 61 | + it 'should set tie breaker' do |
| 62 | + params_from('pizza') do |dismax| |
| 63 | + dismax.tie_breaker = 0.1 |
| 64 | + end[:tie].should == 0.1 |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + private |
| 69 | + |
| 70 | + def dismax(keywords) |
| 71 | + dismax = Soolr::Dismax.new(keywords) |
| 72 | + yield dismax if block_given? |
| 73 | + dismax |
| 74 | + end |
| 75 | + |
| 76 | + def params_from(keywords, &block) |
| 77 | + dismax(keywords, &block).to_params |
| 78 | + end |
| 79 | +end |
0 commit comments