0
votes

I am pretty new to Sphinx.

Trying to find user with name "bob" and company_id "14".

Controller:
@users = User.search 'bob', :conditions => { :company_id => '14'}

Model:
  define_index do
    indexes :name
    indexes :company_id
  end

Error:
index user_core: query error: no field 'company_id' found in schema

I have the 'company_id' in table & I re-indexed everything several times. When I am just searching for the 'name' everything works properly.

3

3 Answers

4
votes

Just as another helpful hint: turns out I had to change the way I called Model.search(), since my field was listed as an attribute (i.e. using has), I needed to call the search method with :with instead of :conditions (for fields).

3
votes

Attributes should be declared as:

has company_id

So, in you case:

Model:
define_index do
    indexes :name
    has :company_id
  end
1
votes

And one more helpful hint, if you happen to be an idiot like me:

If you are getting this error and you are correctly using attributes and fields, it may be that you forgot to restart your dev server after adding a new field to the index.