store multiple date ranges in solr field - database

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?

Related

Keep PivotTable report filter after data refresh

I have a PivotTable (actually it is five PivotTables, each on its own separate sheet) that is created from a query of an outside database. Each of the PivotTables represents a day (i.e. Today, Tomorrow, Today+2, Today+3, and Today+4). For the report filter for the first two, we use a date range filter of today and tomorrow which automatically filters the data and allows it to roll over. We created custom date ranges for the other three days, but upon every external data refresh we have to go into each sheet and reselect the report filter from all to the specified time frame. This data rolls over every day so we can see the lineup for the next 96 hours out.
Is there a way to either keep the PivotTable report filter criteria (VBA and macros are both acceptable, although we are also fairly new to both)?
Or is there some super secret way to extend the report filter from just today and tomorrow to a time range (48 hours, 96 hours) instead of next month?
I need the days to be separated, so next week will not work because all the days will populate on one page.
Without seeing a real example it's hard to tell, but how about changing the query to a relative date index, i.e. something like
SELECT DATEDIFF('day', GETDATE(), report_dt) AS days_from_today FROM reporting_table
And then set your report filters on this relative date index (days_from_today = 1 for tomorrow, etc)? You can always create another Excel column in the report =TODAY() + days_from_today to get your absolute date back. (Assuming you are just dealing with one time zone for reporting purposes.)
I.e., instead of rolling filters, keep the filters on constant indices, and let the indices cover a rolling date range. I'm not sure Excel is smart enough to do the rolling filters thing.

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.

Filtering on two different dates on the same filter in Solr

In Solr, if you have an indexed piece of data, and within that data you had a set of date values, how can you query against the index and ask for events between X and Y date?
For example, if I have a list of Event Venues, each with dozens of events (single, all day, or multi-day), how would you construct the filter to return venues whos events are between the start and end date specified in a search?
Right now, if I search in a form and submit it through to Solr, the query string looks like this:
&fq=dm_event_start_date\:value:["2013-01-04T05:00:00Z" TO *]
&fq=dm_event_end_date\:value:[* TO "2013-01-08T05:00:00Z"]
&fq=bm_tickets_left\:value:"TRUE"
What I really want to ask for are events that occur or start on January 4th, don't last beyond January 8th, AND still have tickets left.
I feel like what I am getting in return is any event that either falls between the two dates, or has tickets available- not necessarily matching the dates.
Probably the date field values needs to be out of the quote in the range query e.g. :-
&fq=dm_event_start_date:value:[2013-01-04T05:00:00Z TO *]
&fq=dm_event_end_date:value:[* TO 2013-01-08T05:00:00Z]
&fq=bm_tickets_left:value:true
Also the bm_tickets_left needs to be just the string value.

Criteria to get last not null record present

I have a daily record table where records are stored date wise. I am using hibernate criteria to access data. How do i get the last date till which records are present continuously (date wise continuity) by providing a date range. For example, say records are there from 21-09-2012 to 25-09-2012 , again from 27-09-2012 to 31-09-2012. I want to form a query using criteria to get record of date 25-09-2012 because for 26-09-2012 there are no records (by passing date ge 21-09-2012 and date le 31-09-2012) . I want to know the last date till which records are present continuously. Say the table has three fields - 1.recordId (AI) 2.date 3.Integer record.
Its not a proper solution to your question. But it may be scenario specific.
How about getting the data for a date range and show then on a calender. Change the color of date if the corresponding value is null.
I think HQL will be better way to this in Hibernate:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html

Sum field by date range

I'm using solr 3.6 and I'm kinda stuck trying to perform a special query.
I'm actually using facets by date range, the face.date.gap is set to +1DAY. Of course, the facet is supposed to return the count of docs at a date range but I also need to get the sum of a special field at the same ranges used in facet. It's like I need to count how many votes I have daily monthly, weekly, whatever... it depends on the gap params.
Any ideas? Should I use the group.query or facet.query?
One suggestion I have is to treat the weeks, days separately, and index them. For ex. Today is part of 24th week. Another suggestion is not to rule out multiple searches to service one request. One to calculate all oth facets and one to return counts for given date range (based on search results from first query).

Resources