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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:01:14+00:00 2026-06-05T20:01:14+00:00

@search = Sunspot.search(Event, Person, Organization) do keywords params[:q] order_by(:score) end Based on the search

  • 0
  @search = Sunspot.search(Event, Person, Organization) do
    keywords params[:q]
    order_by(:score)
  end

Based on the search results I’d like to create a list of Models with counts for each model.

  • Events (12)
  • People (5)
  • Organizations (3)

Is there a way to do this type of grouping in Sunspot?

<% @search.each_hit_with_result do |hit, result| -%>
    <%= result.class %> <!- Gives me Model, but repeated -->
<% end %>
  • 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-06-05T20:01:15+00:00Added an answer on June 5, 2026 at 8:01 pm

    There is probably a smarter way, but one possible way is to get array of the classes like this

    classes = @search.results.map(&:class) # this will give array of returned classes
    

    then do as suggested in this link

    h = Hash.new(0)
    classes.each { | v | h.store(v, h[v]+1) }
    
    # h = { 3=>3, 2=>1, 1=>1, 4=>1 }
    

    hope that helps

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

Sidebar

Related Questions

I'd like to be able to order my search results by score and location.
I am using RABL to output a Sunspot/SOLR result set and the search results
I use the sunspot-rails for search. These is a Rspec looks like: describe GET
I am trying to order the Sunspot search results by price from the smaller
Many search engines are not using meta keywords and Google through many recent updates
How can I use 'or' in a Sunspot search? In my code I have
Trying to implement search with Sunspot Gem wich is using Solr.Fulltext search works fine
I want to search and filter using sunspot. I want to filter using month
I have a rails app that uses Sunspot and Solr for search functionality. I'm
I'm using Sunspot 1.3.0 in a Rails project. Post.search do with(:category_ids, [1, 3, 5])

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.