0

Alright guys. So I want my query in such a way as that it will hit this same filter cache, What I really dont want to do is to calcuate the start of the week in my code and structure the query based on that. Is there a way to get solr to be returning based on the week ?

I couldnt find anything here : http://docs.lucidworks.com/display/lweug/Solr+Date+Format Using [NOW/DAY-7DAYS TO NOW/DAY+1DAY] wont help since it does not know start and end of week.

phonegapnoob
  • 87
  • 1
  • 5

1 Answers1

0

Does involve calculation on client side and formulating query based on that, so, probably not what you are looking for :)

In java (if your week starts on Monday):

client:

(new Date().getTime()-345600000)/604800000 = 2257

query:

select?q=*:*&fq={!frange%20l=2257%20u=2258}div(sub(field(last_update),345600000),604800000)&wt=json&indent=true
user2023507
  • 1,153
  • 12
  • 23
  • Can you please explain what that code is doing. Sorry I dont get it. This is what I am using right now in pysolr "fq=created_dt:[NOW/DAY-"+str(datetime.datetime.utcnow().weekday())+"DAYS TO NOW/DAY+1DAY]" – phonegapnoob Apr 09 '13 at 05:13
  • 604800000 is number of milliseconds in a week. new Date().getTime() will give the number of milliseconds since Jan 1, 1970. Divide that by 604800000 and we get current week number - call it n. If document's last_update field holds the create date of the document, then div(field(last_update),604800000) will give the week in which document was created. It should be between n & n+1. – user2023507 Apr 09 '13 at 06:30
  • Since jan 1, 1970 is a Thursday, I subtracted 4 days from it (345600000 milliseconds) if looking for Monday as start of the week! – user2023507 Apr 09 '13 at 06:33