Skip to content

Instantly share code, notes, and snippets.

@valakirka
Created May 18, 2012 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valakirka/2726260 to your computer and use it in GitHub Desktop.
Save valakirka/2726260 to your computer and use it in GitHub Desktop.
Indexes and custom sphinx_select searches
class NewsEntry < AR::Base
has_one :association
define_index do
index wadus
has association.published_at, :as => :published_at
end
end
class WadusController < AC
def index
# Here I'd like to use my defined filter attribute, but seems like it's
# using the regular 'published_at' attribute of NewsEntry. Is that possible?
published_conditions = "*, if((published_at > NOW() OR published_at = 0), 0, 1) as published"
conditions = {:sphinx_select => published_conditions,
:with => {:published => 1}}
@collection = ThinkingSphinx.search(conditions)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment