Solr - facet by day of week - solr

On Solr, I would like to get facets of a field date but according to a day of the week,
for example, if I have 3 records with the following values on the date field:
16/11
22/11
23/11
I would like to get the following facet:
Sunday: 2,
Monday: 1
Is it possible?

Solr does not having anything which could provide you the day of the week based on the date.
You need to index the weeks data in a separate field.
Where your fields would be holding the values like SUNDAY, MONDAY etc..
Once you have this field and indexed the data in solr.
Then you could be able to achieve the faceting based on the weeks.

Related

store multiple date ranges in solr field

Every day I check which events happened. Each event is represented as a document in Solr index.
An event can happen 4 days in a row, skips a day and then happen the next 4 days and so on... In a typical search query, I need to find all events that happened between start date and end date and also return the date ranges of event occurrence.
In the image above, a search between 1. and 17. would return R1(1-4), R2(6-9) and R3(11-14)
How do you store multiple date ranges in indexed and stored solr field?

Sunspot solr index search and index on range data

I am storing availability timing for my users where they enter for each day of week what timings they would be available
for example - Mr X would be available on
sunday for 2-5, 8-12, 15-18
monday for 1-3, 5-8, 10-12
and so on entire week
what would be the best possible way of indexing and searching this data in solr
a database query for searching such a dataset would be like
select * from schedule inner join days on schedule.day_id = days.id
where days.name = 'Sunday' and schedule.start>=5 and schedule.end>=8
Use the DateRangeField which became available in Solr5. This allows you to query for documents that contain ranges that matches your query time.
fq={!field f=dateRange op=Contains}[2013 TO 2018]
Before Solr 5 there's a neat hack that uses the spatial support in Solr to query for overlapping durations (if this point is contained within the expected time area, etc.).
Depending on the needed resolution, you could also index seven different fields (monday - sunday) and then index an integer for each hour that the person is available. You can then query the field with a regular query, such as available_sunday:15 to find matching persons.

Solr Date Range Facets not returning results till current date

So my Solr date range query is as follows:
&facet.range=date&facet.range.start=NOW/DAY-36MONTH&facet.range.end=NOW/MONTH&facet.range.gap=%2B1MONTH
However the facets I am getting for the date is till last month, say today is 23rd December and I am getting it till 23rd November. How should I modify my query to obtain results till today?
So the correct portion of the query is in BOLD &facet.range=date&facet.range.start=NOW/DAY-36MONTH&facet.range.end=NOW/MONTH+1MONTH&facet.range.gap=%2B1MONTH
Note that + has to be escaped.

Solr match any date in given month

In Solr, is it possible to search for all records in a given month regardless of the year or day ? For example, the snippet below would match everything on 01.01.2013 - what I want to do is find everything that appeared on 01.01 for any year.
date:2013-01-01T00:00:00Z
No, not with a date field. Solr can only deal with ranges of dates, just like it only deals with ranges of numbers or ranges of strings. Asking Solr to only query a date field based on the first day of the month is like asking it to query on a numeric field and only give you odd numbers, or querying a string but only those starting with vowels.
What you'll need to do is break up the date into month and day components and then query on those. If your base field is sale_date, you'll also need sale_month and sale_day. Then you can query on month:3 to get everything that happened in any March, or day:1 and get everything for the first day of any month or month:3 AND day:1 to get everything that happened on any March 1st.

SOLR travel site: on date queries

I was looking to implement SOLR for a Hotel bookings site. Search based on location, hotel names, facilities works very well and so does the faceting. What I have not been able to figure out is how to search for a hotel given Checkin and Checkout dates.
Eg: User will search for search query - "Hotels in Newyork" and select CheckIn Date: 10th Feb 2012 and CheckOut Date: 12 Feb 2012 from the date selection box.
This is how I have the data -
Hotel_Name 10thFeb2012 11thFEB2012 ........ 31DEC2012
Hotel1 2room 3room 10rooms
Hotel2 1room 4room ........ 12rooms
Now if the query is for Hotel2 for 3rooms from checkin Date 10thFeb2012 to 11thFeb2012 it shdnt match because there is only one room available for 10thFeb.
IF the query for Hotel2 is for 1 room from checkin Date 10thFeb2012 to 11thFeb2012 then it should be part of search result.
Use the ISO 8601 format for your date-times.
Complete date plus hours, minutes, seconds and a decimal fraction of a second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45Z)
Both your database and Solr will understand date-times from strings that conform to that format.
So,
store the data in DB and Solr with compatible date-time formats. (On the back of my head, Solr must have a Z appended to the date-time, else its invalid).
your search interface must format all dates in that format to query solr.
Solr can do conditional expressions, facets, range bucket faceting etc with dates.
I would go with the following schema:
hotel_name : string (for faceting)
hotel_name_searchable : text (for searching, this is a copy field:look it up)
room_id : string
start_date : date (when the room is availabe)
end_date : date (if not booked, set it to an infinite date, say 2040)
For each room you are ever tracking, store the date-times between which it is free.
You can search for rooms between the start_date and end_date.
Do faceting on hotel_name so your search for rooms "checkin Date 10thFeb2012 to 11thFeb2012" gets you:
Hotel1:[r1,r2,r3]
Hotel2:[r8]
Hotel3:[r2,r3,r4]
Faceting on hotel_name filters to one hotel, facet.mincount on room_id can return hotels having the required number of rooms.
A little warning: I may be a bit rusty on faceting, as I used to do a lot of processing on Solr results itself.

Resources