How do I add the condition "IS NOT NULL" to a Thinking Sphinx search
Asked Answered
C

1

9

I'm using Thinking Sphinx for full-text search, following this video.

I'd like to do the following:

@articles = Article.search(params[:search], :conditions => "published_at IS NOT NULL", :order => :created_at)

The problem is that this doesn't work. It seems that the search method only accepts conditions that are a hash. I've tried a couple of ways, but I am clueless as to how I can represent "published_at IS NOT NULL" as a hash...

Catacomb answered 3/11, 2008 at 11:27 Comment(0)
C
24

Was given the solution over at Railscasts

If you want *all* results for that model to filter out records where published_at IS NULL, add 'where "published_at IS NOT NULL"' to your define_index block.

If it's only sometimes, add published_at as an attribute, and then sphinx should store null dates as 0's, so you can filter using :without => {:published_at => 0}

The second solution was what I needed.

Catacomb answered 3/11, 2008 at 14:11 Comment(1)
Is this answer still valid for ThinkingSphinx 3.2 @pat ? without => {:published_at => 0} does not seem to work anymoreAldous

© 2022 - 2024 — McMap. All rights reserved.