Solr match any date in given month - solr

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.

Related

Power BI: Week #'s not sorting properly

I am having trouble with a line graph visual, where the data is organized by week number and by year number. However when I put the information into the visual and try viewing both 2020 & 2021, it rearranges the data in the order of 2021 & 2020. How do i get it to properly see the data in the correct order of week number by year?
I tried sorting the week # by an index value, also by year, also by week... with no luck
From the images it looks like there is no sort on the year and week, just by the week.
You need to add a column that has a year week key, that you can sort by.
For example 202101 for the week one of 2021.
Assuming you have a date like dd/mm/yyyy format, for example 11/04/2021 in DAX you can use:
YearWeek = YEAR('Table'[Date]) & WEEKNUM('Table'[Date])
This should now sort the data correctly. If you want you can add another column, that is more user friendly like WK01-2021, if you wish, you can then sort by that column, or use the new key column to sort the textual one.
If you just have a year and week column, create a new column that concatenates the two.
For this you should have a Calendar table, that contains a the date groupings that you you need. For example using CALENDARAUTO or you can do it in Power Query here or here.
This actually does not give the correct sequence, when you are dealing with single digit week numbers. For example when dealing with the first ten weeks of 2020, the sequence would be 20201, 202010,20202, 20203... which is obviously wrong.
Here you need a double digit Week number, so a small change in the suggested formula should do it:
YearWeek = YEAR('Table'[Date]) & FORMAT(WEEKNUM('Table'[Date]),"00")
The sequence should now work.

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...

Representation of repetitive dates in SQL database

In my program I must manage some holidays. Each holiday can be an exact date, or a repetitive date.
For example:
-6th January of each years
-first day of each month of each year
How would you I save this information on db?
I can't use Datetime because with datetime I can't represent the particular cases like in the above example.
Any suggestion?
If it may concern, I am using TSQL
Sorry for my poor english.
The simple approach, without knowing more about your usage of these data, will be to have three numeric fields day, month, year and interpret them this way: If all three are filled, it's exactly that day and no other day. If year isn't filled, it's the day and month, repeating every year. If only the day is filled, it's the day, repeating every month.
If you have more intricate repetition schemes, you'll need an attribute for the repetition rule, like "every three months".
Of course, every query will need to contain some logic to interpret this scheme, but that's inevitable, unless you decide to have a list of all holidays, say the next 50 years.
I would suggest a 3 column design to store this conditions
Column to Specify whether this is a Day or WeekDay
Column to Specify Day/WeekDay Number (ie 1 to 30/31 for Day, 1 to 7 for WeekDay)
Column to Specify Monthly/Yearly occurrence.(means every month/year)
Eg:- For first day of each month,Something like this : DAY,1,MONTHLY
For Second Saturday of every month : WEEKDAY,14*,MONTHLY (*My Week start is Sunday)
This is not a perfect solution, you may have to add some more column to meet your business logic completely.

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.

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