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 7058155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:04:43+00:00 2026-05-28T04:04:43+00:00

I’m searching in two different modes using Thinking Sphinx: Full search on a single

  • 0

I’m searching in two different modes using Thinking Sphinx:

  1. Full search on a single model for normal search functionality
  2. Full search across all models for autocomplete dropdown functionality

For the sake of this question, let’s say I have a Person and a Country model.

When performing regular searches, I want to fetch all people who’s name of country name matches the search string. To achieve this, I have added an index on the countries name in the Person index. All well so far.

When searching to populate my autocomplete dropdown, I want to show all countries and all people matching my search string. Here the problem shows up. When doing an Application-Wide search, I now get:

  1. all countries whose name match my search string
  2. all doctors whose name match my search string, and unfortunately…
  3. all doctors who belongs to a country that matches the search string.

The last part makes for some really confusing autocomplete results for the user. Is there any simple way for me to avoid this by using built-in functionality, for example like having two indices on the Person model, and choose which one to use for each kind of search?

  • 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-28T04:04:44+00:00Added an answer on May 28, 2026 at 4:04 am

    I supposed that your models are like the below:

    class Person < ActiveRecord::Base
      belongs_to :country
      define_index
        indexes :name
        indexes country(:name), :as => country_name
      end
    end
    
    class Country < ActiveRecord::Base
      has_many :people # has_many :persons # depending on your singular/plural case
      define_index
        indexes :name
      end
    end
    

    So, you can get the result without having 3(third condition) by executing the query:

    ThinkingSphinx.search :conditions => {:name => params[:q]}, :classes => [Person, Country]
    

    But, if you want to create multiple indexes on a model it can be done like the sample below:

    class Person < ActiveRecord::Base
      belongs_to :country
      define_index :my_first_in do
        indexes :name
        indexes country(:name)
      end
      define_index :my_second_in do
        indexes :name
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I am using Paperclip to handle profile photo uploads in my app. They upload

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.