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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:41:05+00:00 2026-05-26T01:41:05+00:00

The use case is this: I’d like to let my user search from a

  • 0

The use case is this:

I’d like to let my user search from a single text box, then on the search results page organize the results by class, essentially.

So for example, say I have the following models configured for Thinking Sphinx: Post, Comment and User. (In my situation i have about 10 models but for clarity on StackOverflow I’m pretending there are only 3)

When i do a search similar to: ThinkingSphinx.search 'search term', :classes => [Post, Comment, User] I’m not sure the best way to iterate through the results and build out the sections of my page.

My first inclination is to do something like:

  1. Execute the search
  2. Iterate over the returned result set and do a result.is_a?(ClassType)
  3. Based on the ClassType, add the item to 1 of 3 arrays — @match_posts, @matching_comments, or @matching_users
  4. Pass those 3 instance variables down to my view

Is there a better or more efficient way to do this?
Thank you!

  • 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-26T01:41:06+00:00Added an answer on May 26, 2026 at 1:41 am

    I think it comes down to what’s useful for people using your website. Does it make sense to have the same query run across all models? Then ThinkingSphinx.search is probably best, especially from a performance perspective.

    That said, do you want to group search results by their respective classes? Then some sorting is necessary. Or are you separating each class’s results, like a GitHub search? Then having separate collections may be worthwhile, like what you’ve already thought of.

    At a most basic level, you could just return everything sorted by relevance instead of class, and then just render slightly different output depending on each result. A case statement may help with this – best to keep as much of the logic in helpers, and/or possibly partials?

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

Sidebar

Related Questions

My Use case like this - User is in my application - User presses
I have this use case of an xml file with input like Input: <abc
The use case is some what like this: public class SomeClass : ICloneable {
My use case is this, I want to call out to a webservice and
My use case is this... I have a project that has two production branches.
I have a use case with NServiceBus explained in this question. Essentially there is
I'm starting to use Mercurial on my web server (in this case MediaTemple's Grid).
How can I use output caching with a .ashx handler? In this case I'm
Use case: A does something on his box and gots stuck. He asks B
The original use case: This is a possible use case I'm trying to solve:

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.