Question

With V3, I can't display facets :s :

I use Rails 4.0.1, thinking-sphinx (3.0.6), and sphinx was recently installed on MacOS 10.9 with 'brew install sphinx --mysql'

I defined my index this way :

ThinkingSphinx::Index.define :user, with: :active_record, delta: ThinkingSphinx::Deltas::DelayedDelta do

  #attributes
  has 'users.banned_at IS NULL and users.email_verified_at IS NOT NULL', as: :searchable, type: :boolean, facet: true
  has 'RADIANS(geo_latitude)', as: :latitude, type: :float
  has 'RADIANS(geo_longitude)', as: :longitude, type: :float

  has gender, facet: true
end

in my controller :

@users = User.search with: {geodist: 0.0..100_000.0},
                         geo: [City.first.latitude, City.first.longitude]
@facets = @users.facets

and then in my view (HAML syntax) the same code as V2, which render me nothing :

-@facets.each do |facet, facet_options|
  - %h5= facet
  -  %ul
    -facet_options.each do |option, count|
      -%li= link_to "#{option} (#{count})" (...)

@facets.inspect give me this :

{:geodist=>0.0..100000000.0}, :geo=>[46.15, 4.91667], :classes=>[User(id: integer, gender: integer, name: string, family_name: string, email: string, crypt_pass: string, salt: string, auth_token: string, verif_token: string, password_reset_token: string, password_reset_sent_at: datetime, city_id: integer, oauth_provider: string, oauth_uid: integer, oauth_token: string, oauth_expires_at: datetime, last_login_at: datetime, banned_at: boolean, created_at: datetime, updated_at: datetime, schedule_mon_0: boolean, schedule_mon_1: boolean, (...) schedule_available_holidays: boolean, destroyed_email: string, destroyed_at: datetime, birthday: date, mobility_km: integer, geo_search: string, geo_latitude: float, geo_longitude: float, geo_streetnumber: string, geo_route: string, geo_locality: string, geo_postal_code: string, geo_administrative_area_level_2: string, geo_administrative_area_level_1: string, geo_country: string, geo_type: string, email_verified_at: datetime)]}, @query="", @hash={}>

I tried to make @facets.to_hash but it give me this error :

Using the old-fashion @variables (@count, @weight, etc.) is deprecated

I'm stuck with this problem, many thanks for your help !

Was it helpful?

Solution

You're very likely using Sphinx 2.1.2, which was recently released. Sphinx's idea of deprecation is a little odd (raising errors instead of warnings), but TS v3.0.6 has the ability to switch over to the new syntax. This is covered in the release notes: https://github.com/pat/thinking-sphinx/releases/tag/v3.0.6.

If you're still having issues after making the changes outlined there, do let me know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top