Sebastien
Sebastien

Reputation: 6660

How to filter with a month range using sunspot

I want to search and filter using sunspot. I want to filter using month number on a date field "date_start". How can i filter using just the month part of my date field?

I tried something like this :

with(:date_start).greater_than(3) 

Thank you for help

Upvotes: 0

Views: 290

Answers (1)

Andrey Kryachkov
Andrey Kryachkov

Reputation: 901

Add a virtual attribute to your model, for example:

def month
  self.date_start.strftime('%m')
end

Then add it to index and search it!

Upvotes: 2

Related Questions