Sha256: 6544df3db91123f4871342973a98912e3a9ad0f9e233151d2403a204ad27912f

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require 'acceptance/spec_helper'

describe 'Accessing attributes directly via search results', :live => true do
  it "allows access to attribute values" do
    Book.create! :title => 'American Gods', :year => 2001
    index

    search = Book.search('gods')
    search.context[:panes] << ThinkingSphinx::Panes::AttributesPane

    expect(search.first.sphinx_attributes['year']).to eq(2001)
  end

  it "provides direct access to the search weight/relevance scores" do
    Book.create! :title => 'American Gods', :year => 2001
    index

    search = Book.search 'gods', :select => "*, weight()"
    search.context[:panes] << ThinkingSphinx::Panes::WeightPane

    expect(search.first.weight).to eq(2500)
  end

  it "can enumerate with the weight" do
    gods = Book.create! :title => 'American Gods', :year => 2001
    index

    search = Book.search 'gods', :select => "*, weight()"
    search.masks << ThinkingSphinx::Masks::WeightEnumeratorMask

    expectations = [[gods, 2500]]
    search.each_with_weight do |result, weight|
      expectation = expectations.shift

      expect(result).to eq(expectation.first)
      expect(weight).to eq(expectation.last)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinking-sphinx-4.1.0 spec/acceptance/attribute_access_spec.rb
thinking-sphinx-4.0.0 spec/acceptance/attribute_access_spec.rb