Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7614373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:23:15+00:00 2026-05-31T02:23:15+00:00

I have a following model: class Article < ActiveRecord::Base define_index do indexes content indexes

  • 0

I have a following model:

class Article < ActiveRecord::Base

  define_index do
    indexes content
    indexes :name, sortable: true
    has type
  end
end

and special type of an article is:

class About < Article
end

and the same for Contact

I would like to have searchable articles index action without articles with type of “About” or “Contact”

class ArticlesController < ApplicationController
  load_and_authorize_resource

  def index
    @articles = Article.search(params[:search],
                               :with_all => {:type => nil},
                               :page => params[:page],
                               :per_page => 10)
  end
end

But the @articles instance variable contains everytime also “About” & “Contact” articles.

This is very strange (seems like will_paginate messing everything up):

@articles = Article.search(
  :without =>  {:type => %w(About Contact)}).include?(About.first) # false

@articles = Article.search(
  :without =>  {:type => %w(About Contact)},
  :page => 1,
  :per_page => 1000).include?(About.first) # true

=============================================================================

Finally I did:

class Article < ActiveRecord::Base

  define_index do
    indexes content
    indexes :name, sortable: true

    has "CRC32(type)", :as => :article_type, :type => :integer
  end
end

and:

class ArticlesController < ApplicationController

  load_and_authorize_resource

  def index
     @articles = Article.search(params[:search],
                               :without =>  {:article_type => ["About".to_crc32, "Contact".to_crc32]},
                               :page => params[:page],
                               :per_page => 10)
  end
end

and it works. Thanks guys!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:23:18+00:00Added an answer on May 31, 2026 at 2:23 am

    From the Thinking Sphinx FAQ:

    Filtering on String Attributes

    While you can have string columns as
    attributes in Sphinx, they aren’t stored as strings. Instead, Sphinx
    figures out the alphabetical order, and gives each string an integer
    value to make them useful for sorting. However, this means it’s close
    to impossible to filter on these attributes.

    So, to get around this, there’s two options: firstly, use integer
    attributes instead, if you possibly can. This works for small result
    sets (for example: gender). Otherwise, you might want to consider
    manually converting the string to a CRC integer value:

    has "CRC32(category)", :as => :category, :type => :integer

    This way, you can filter on it like so:

    Article.search 'pancakes', :with => { :category => 'Ruby'.to_crc32 }

    Of course, this isn’t amazingly clean, but it will work quite well.
    You should also take note that CRC32 encoding can have collisions, so
    it’s not the perfect solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok say I have the following model: class Country < ActiveRecord::Base validates_presence_of :name validates_presence_of
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I have the following (heavily simplified) model, that uses will_paginate class Search < ActiveRecord::Base
I have the following model: class Deck < ActiveRecord::Base has_many :cards serialize :stats attr_accessible
I have following models relation: class Section(models.Model): section = models.CharField(max_length=200, unique=True) name = models.CharField(max_length=200,
I have a following model class Order < ActiveRecord::Base has_many :products, :through => :line_items
I have the following Django 1.2 models: class Category(models.Model): name = models.CharField(max_length=255) class Article(models.Model):
I have the following model: class User: name = models.CharField( max_length = 200 )
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
I have the following in my model: class info(models.Model): add = models.CharField(max_length=255) name =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.