Odd behaviour on heroku / flying sphinx with filter attribute

David RIce's Avatar

David RIce

10 Feb, 2011 07:19 AM

Okay, so I have a bunch of models I am doing an application wide search on. We want to be able to filter by an attribute (sector_id) however there are some models in the index without this. I was getting some errors. so I added the following to their define_index block.

has "case id when true then 0 end", :as => :sector_id, :type => :integer

Works perfectly with regular thinking_sphinx locally, however. On heroku with flying sphinx I get the following error

ActionView::Template::Error (no such filter attribute 'sector_id'):

This is raised when accessing the @results instance variable.

I have been able to track it down to happen in this scenario, when there are no results returned for the query parameter, and the :with filter is added it will throw the error.

So I've managed a workaround by first performing the query without the filter and then performing it again if we get an initial result.

Would be good to not have to do this!

  1. Support Staff 1 Posted by Pat Allan on 10 Feb, 2011 11:39 AM

    Pat Allan's Avatar

    Hi David

    Just looking at your logs - I think the problem is 'id' in your SQL snippet is ambigious, so indexing has failed for some models. Might want to add the table prefix :)

    Let me know if that fixes things - and don't forget to use fs:rebuild, so the Sphinx daemon is aware of the changes as well (although it's possible Sphinx 1.10-beta is smarter about that, not sure).

  2. Pat Allan closed this discussion on 10 Feb, 2011 11:39 AM.

  3. David Rice re-opened this discussion on 11 Feb, 2011 07:30 AM

  4. 2 Posted by David Rice on 11 Feb, 2011 07:30 AM

    David Rice's Avatar

    I changed the snipped and rebuild the index but am getting the same error. Just to double check, is this correct?

    has "case `users`.`id` when true then 0 end", :as => :sector_id, :type => :integer
    

    Still works locally.

    Sphinx 0.9.9-release (r2117)
    latest ts / fs

  5. Support Staff 3 Posted by Pat Allan on 11 Feb, 2011 07:35 AM

    Pat Allan's Avatar

    ` is for MySQL - you need to use double-quotes for PostgreSQL:

    case "users"."id"
    

    You can find the indexing logs in your dashboard (log in to Heroku, select your app, then in the add-ons drop down on the top right, select Flying Sphinx), which will show you the indexing errors.

  6. 4 Posted by David Rice on 11 Feb, 2011 08:38 AM

    David Rice's Avatar

    Okay, so I gave up on trying to maek a virtual attribute and just added sector_id column to the models that didn't have it and defaulted the field to zero.

    Works!

    Somehow both approaches feel wrong to me, perhaps there is something underlying in thinking sphinx that could ignore if the result set doesn't have that column?

    I didn't know there was a login for flyingsphinx that I could get, will make things a lot easier. Nice work!

    Cheers!

  7. Support Staff 5 Posted by Pat Allan on 11 Feb, 2011 11:30 AM

    Pat Allan's Avatar

    Great to know you got it working - for future reference, though: It's actually a requirement of Sphinx that attributes used in filters, ordering, etc should exist across all indexes being searched. So TS can't work around that, I'm afraid.

    However, creating a dummy attribute is easy - I should have thought of this back when you first posted the ticket:

    has "0", :as => :sector_id, :type => :integer
    

    And of course in models with that column:

    has sector_id
    

    Cheers :)

  8. Pat Allan closed this discussion on 11 Feb, 2011 11:30 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac