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

  • Home
  • SEARCH
  • 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 590219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:30:20+00:00 2026-05-13T15:30:20+00:00

I installed Sphinx and Thinking Sphinx for ruby on rails 2.3.2. When I search

  • 0

I installed Sphinx and Thinking Sphinx for ruby on rails 2.3.2.

When I search without conditions search works ok. Now, what I’d like to do is filter by tags, so, as I’m using the acts_as_taggable_on plugin, my Announcement model looks like this:

class Announcement < ActiveRecord::Base

  acts_as_taggable_on :tags,:category

  define_index do
    indexes title, :as => :title, :sortable => true
    indexes description, :as => :description, :sortable => true
    indexes tags.name, :as => :tags
    indexes category.name, :as => :category

    has category(:id), :as => :category_ids
    has tags(:id), :as => :tag_ids
  end

For some reason, when I run the following command, it will bring just one announcement, that has nothing to do with what I expect. I’ve got many announcements, so I expected a lot of results instead.

Announcement.search params[:announcement][:search].to_s, :with => {:tag_ids => 1}, :page => params[:page], :per_page => 10

I guess something is wrong, and it’s not searching correctly.

Can anyone give my a clue of what’s going on?

Thanks,
Brian

  • 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-13T15:30:20+00:00Added an answer on May 13, 2026 at 3:30 pm

    Thinking Sphinx relies on associations in model. In common situations you only have to put index definition below your associations.

    With acts_as_taggable_on plug-in you don’t have tag-related associations in model file and when you write

    indexes tags.name, :as => :tags

    TS interprets it like:

    CAST(`announcements`.`name` AS CHAR) AS `tags`
    

    (look at sql_query in development.sphinx.conf, in my case).
    I suppose that you have attribute name in model Announcement and don’t run into error when rebuild index.

    But we expect:

    CAST(GROUP_CONCAT(DISTINCT IFNULL(`tags`.`name`, '0') SEPARATOR ' ') AS CHAR) AS `tags`
    

    and:

    LEFT OUTER JOIN `taggings` ON (`announcements`.`id` = `taggings`.`taggable_id`)  
    LEFT OUTER JOIN `tags` ON (`tags`.`id` = `taggings`.`tag_id`) AND taggings.taggable_type = 'Announcement'
    

    To get things working just add tag-related associations in your model before you rebuild index:

    class Announcement < ActiveRecord::Base
    
      acts_as_taggable_on :tags,:category
    
      has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag, :class_name => "ActsAsTaggableOn::Tagging",
                :conditions => "taggings.taggable_type = 'Announcement'"
      #for context-dependent tags:
      has_many :category_tags, :through => :taggings, :source => :tag, :class_name => "ActsAsTaggableOn::Tag",
              :conditions => "taggings.context = 'categories'"
    

    In define_index method:

    indexes category_tags(:name), :as => :tags
    has category_tags(:id), :as => :tag_ids, :facet => true
    

    In controller:

    @announcement_facets = Announcement.facets params[:search], :with => {:tag_ids => [...]} 
    @announcements = @announcement_facets.for.paginate( :page => params[:page], :per_page => 10 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 397k
  • Answers 397k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer lowercase c for the clicked signal. connect(ui.treeView,SIGNAL(clicked(const QModelIndex& ) ),… May 15, 2026 at 3:16 am
  • Editorial Team
    Editorial Team added an answer I don't use Netbeans and I'm not quite sure I… May 15, 2026 at 3:16 am
  • Editorial Team
    Editorial Team added an answer As long as they will all fit in memory, a… May 15, 2026 at 3:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.