How does NOW/DAY in a Solr query work? - solr

I am trying to figure out why Solr thinks an doc is in the past. My query is set up to use
published:[* TO NOW/DAY]
The doc I am hoping it will find has a published date of
2012-04-30T04:00:00Z
Current Solr server time is Mon Apr 30 18:26:47 EDT 2012. My understanding says that the document should have been found by now, which makes me think the NOW/DAY doesn't work the way I think it does. Does anybody know how the NOW/DAY evaluates dates and why when Solr is not finding my doc when I add that stipulation?

NOW/DAY means take the actual date time and round it to the day (leaving out the time). Of course if the actual date is 2012-04-30, any hour, the result is 2012-04-30T00:00:00Z.

Try just using NOW. I suspect that NOW/DAY is equal to 2012-04-30T00:00:00Z.

NOW/DAY rounds down to midnight last night. If you want the midnight of current day change with NOW+1DAY/DAY.
Date Math Syntax
Date math expressions consist either adding some
quantity of time in a specified unit, or rounding the current time by
a specified unit. expressions can be chained and are evaluated left to
right.
For example: this represents a point in time two months from
now:
NOW+2MONTHS
This is one day ago:
NOW-1DAY
A slash is used to indicate rounding. This represents the beginning of the current hour:
NOW/HOUR
The following example computes (with millisecond precision)
the point in time six months and three days into the future and then
rounds that time to the beginning of that day:
NOW+6MONTHS+3DAYS/DAY
Note that while date math is most commonly used relative to NOW it can
be applied to any fixed moment in time as well:
1972-05-20T17:33:18.772Z+6MONTHS+3DAYS/DAY
Quoted from Apache Solr Reference Guide - Working with Dates

Related

Pull a Date from a comment

Good Morning All.
I have a comment field from an invoice system. The user goes into the invoice and leaves a comment/note on it. The source system tags each note with a date. However, the month is either a single digit or a double digit based on the date the note was entered same with the day. So the issue I am having is that I want to pull all of the invoice notes that start with a certain time period. So the notes always start like either one of these:
6/7/16 7:51 AM
11/11/16 8:11 PM
Is there a way to pull the date from the beginning of the note say using AM or PM as the starting point and working back to the beginning of the string?
What I can tell is that you might use Regular Expressions to extract the date from the string, but SQL server doesn't support the regular expression!
A work around is to use CLR, here an article that explain how to achieve what you want. Regular Expressions in MS SQL Server 2005/2008
To get some help on how to build the regular expression to match the dates, here another article that might help you : Regular Expression Library
The date regular expression could be ((\d{2})|(\d))\/((\d{2})|(\d))\/((\d{2})) ((\d{2})|(\d)):((\d{2})|(\d)) [AP]M
Hope this will help you

Limiting datediff by Hours and Days

Long time lurker and now i have my first question:
I'm designing a SQL Report. One Task is to calculate the amount of minutes between two Times. They can be the same day or on different days. In the Database there are 4 Columns given
The Start Date (as Datetime e.g. 24.10.2017 00:00:00)
The Start Time (as Datetime e.g. 01.01.1899 11:25:00)
The End Date (formated as above)
The End Time (formated as above)
I'm calculating three Filds, all in Minutes
Days between: =DateDiff("n", Fields!StartDatum.Value,Fields!QualDatum.Value)
Minutes between: =DateDiff("n",Fields!StartZeit.Value,Fields!QualZeit.Value)
Adding those up: =Fields!QualiZeitTage.Value+Fields!QualiZeitMinuten.Value
All of this is working great and produces the desired output.
My Problem is, that i don't need the full time between those events. I only want to count minutes that are between 7:00 am and 8:00 pm. Also, i want to exclude Saturdays and Sundays. How would i go about limiting the datediff function to my desired times?
Second Problem: The Endtime and Date are only written when the event actually is finished. If it's still ongoing those Fields are empty producing a negative number (-1060764480 for example). Since i'm only using those to produce Boolean output on surpassing a certain length, it's no problem. I would like to handle that more "cleanly" though. Any thoughts?

Solr calculate last day of month

I am building a Solr
Index where data has date I need to calculate a field if date was last day of month?
I would prefer if I can do
It at query time, tried few things unsuccessfully any ideas
if you mean 'a field that says if the date in another field is the last day of THAT month', then it makes much more sense to do it at index time:
it will be more performant, you index it as a boolean, and no calculation needs to happen at query time, just matching it
you have several of ways to compute it: at the client side (the easiest), in a UpdateRequestProcessor, tansformer if you are doing DIH,
maybe some crazy regex can do it in a copyfield...

SOLR date range query for multiple years

I need to implement SOLR date ranges and trying to understand the following 2 conditions from SOLR wiki -
pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]
createdate:[1976-03-06T23:59:59.999Z/YEAR TO 1976-03-06T23:59:59.999Z]
Im really concerned about the "/" operator within the date ranges..
Can someone explain ?
/DAY simply means: use 00:00:00 of that day. Without /DAY, it would be the current time minus 1 year. For the upper boundary, the NOW/DAY+1DAY means: use today, 00:00:00 and add 1 day, which results in tomorrow, 00:00:00.
With /YEAR, it is basically the same: it goes back to January, 1st, 00:00:00 of that year.
You can see this yourself by using debugQuery and taking a look at the timestamps in the querystring.

How to get last year's same week data in SOLR

How do I get last years same week data?
I used fq=trans_date:[NOW-1YEAR/DAY-7DAY TO NOW-1YEAR/DAY] on date field which will give me last 7 days data for last year. But that approach doesn't take into account calender weeks.
It's probably easier to calculate the boundaries for your week number last year in the frontend and then query Solr with the date interval. That way you can get the behavior you want regarding sundays/mondays as well.
Solr does not provide a nice way to do this.
It would be really cool if you could do fq=trans_date:[NOW-1YEAR/WEEK TO NOW-1YEAR/WEEK] but this is not supported.
Nevertheless, you could create a quick function using php or javascript using each language's native Date operators and get the Week number from today to produce start and end points to feed solr in a query like [1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z].

Resources