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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:32:35+00:00 2026-05-20T08:32:35+00:00

I am using Sunspot to search for events (parties, concerts, …) in a Ruby

  • 0

I am using Sunspot to search for events (parties, concerts, …) in a Ruby on Rails 3 application.

I have managed to set up free text search and facet search on a couple of different category types.

Now, I am stuck with my next task. I want to set up facets related to when the event is occuring.

I want to have facets describing both relative date/time ranges such as “today”, “this weekend”, “next weekend” and absolute date/time ranges, such as “Easter Holiday 2011”, “New Years Day 2012”, … The datetime ranges are sometimes overlapping each other.

I have browsed around in the Sunspot API documentation, the Sunspot wiki, here at Stackoverflow, read and loads of articles and blogs. People are writing it is possible to to achieve but I find no examples or implementation ideas that makes me understand how to do this.

Any suggestions?

Since my problem is not in my code, I don’t publish any code. The class Event has a DateTime instance named “start_time”. I do understand it’s my job to define when the absolute date/time ranges appear in the calender.

Best regards,

./stefan

PS Did I tell I’m a newbie? 😉 DS

  • 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-20T08:32:35+00:00Added an answer on May 20, 2026 at 8:32 am

    You should set up your fields as trie time fields for efficient range queries:

    class Event
      searchable do
        time :start_time, :trie => true
      end
    end
    

    Then you can use query facets to facet based on ranges:

    Event.search do
      facet :start_time do
        bod = Time.zone.now.beginning_of_day
        row :today do
          with :start_time, bod..(bod + 1)
        end
        row :tomorrow do
          with :start_time, (bod + 1)..(bod + 2)
        end
        # etc.
      end
    end
    

    The key insight here is that you can construct facets using arbitrary scopes. Note that the facet name :start_time is just used to reference the facet in the search results, and the row labels :today and :tomorrow are similarly just used on the client side to identify the row counts corresponding to those queries; they have no meaning from Solr’s standpoint, so you can call them whatever you want (using whatever data type you want — they don’t have to be symbols).

    More information on query facets here: http://sunspot.github.com/docs/Sunspot/DSL/FieldQuery.html#facet-instance_method

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

Sidebar

Related Questions

I'm accessing Solr in a Ruby on Rails application by using rsolr (not Sunspot).
I'm using Sunspot 1.3.0 in a Rails project. Post.search do with(:category_ids, [1, 3, 5])
I have a rails app that uses Sunspot and Solr for search functionality. I'm
Hi I have been using the normal rails active record LIKE search in my
Simple question, How do I search multiple models using Sunspot?...I'm using Sunspot with Rails,
I'm using Solr with Sunspot (ruby) and due to other constraints i have to
I'm using the Geocoder and Sunspot gem in my application and I have a
I am using RABL to output a Sunspot/SOLR result set and the search results
I am using Sunspot (Ruby/Rails) on top of SOLR in my webapp. Now I
How can I debug Solr search queries when using the Sunspot gem on Rails?

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.