How to get last year's same week data in SOLR - 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].

Related

How should I dynamically query the data per month?

I'll be using reactjs and chartjs to create this. Though I do not have the codes yet, I would only like to ask for advice or to have a better understanding before coding it. In firestore, I already have this data:
I wanted to dynamically query it per vaccine and per month. What I somewhat thought of to do was to have a selection for the user to choose what year and what type of vaccine. I kind of thought of these codes however, dynamically querying it per month was quite difficult:
the selectedVaccine - is the variabale for the select where users can choose what type of vaccine.
db.collection("users") .where("doses.selectedVaccine","==", selectedVaccine) .where("doses.firstDose","==", true)
Any advice would be appreciated about querying it per month. Thank you.
db.collection("users")
.where("doses.selectedVaccine","==", selectedVaccine)
.where("doses.firstDose","==", true)
.where("doses.firstDose", ">=" start)
.where("doses.firstDose", "<" end);
// change doses.firstDose to whichever date you want to use.
For any start and end date (e.g 1st Jan 2020 and 31st Dec 2020), the above query should return all first doses within that time frame.
Then you can loop through the results and place them in arrays depending on their months. Array of all Januaries first doses in position 0, Array of all Februaries first doses in position 1 etc.
This will involve downloading the full data of all doses for a year. If your intention is just to plot a chart, then consider this solution

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

What is the optimized way for queries on partial dates in GAE Text Search?

Need to get entities filtering by month instead of complete date values (E.g. Birthdays) using Google App Engine Text Search. On verifying GAE docs, I think it is not possible to query date fields by month directly.
So in order to filter them by month/date, we consider saving each date sub value like Date(DD), Month(MM) and Year(YYYY) as separate NUMBER field along with complete date field.
I verified locally that we can achieve by saving like this. But is this the correct way of saving dates by splitting each field when we want to query on date sub values?
Is there any known/unknown limit on number of fields per document apart from 10GB size limit in GAE Text Search?
Please suggest me.
Thanks,
Naresh
The only time NUMBER or DATE fields make sense is if you need to query on ranges of values. In other cases they are wasteful.
I can't tell from your question exactly what queries you want to run. Are you looking for a (single) specific day of the month (e.g., January 6 -- of any year)? Or just "anything in June (again, without regard to year)"? Or is it a date range: something like January 20 through February 19? Or July 1 through September 30?
If it's a range then NUMBER values may make sense. But if it's just a single specific month, or a single month and day-of-month combination, then you're better off storing month and day as separate ATOM fields.
Anything that looks like a number, but isn't really going to be searched via a numerical range, or done arithmetic on, isn't really a number, and is probably best stored as an ATOM. For example, phone numbers, zip codes (unless you're terribly clever and wanting to do something like "all zip codes in San Francisco look like 941xx" -- but even then if that's what you want to do, you're probably better off just storing the "941" prefix as an ATOM).

How can I aggregate date data with EntityFramework but without skipping entries with no data?

How can I aggregate data by week with EntityFramework but without skipping weeks for which there is no data? So, basically if there is no data for given week - I want to get 0 or NULL as a result for that week.
Agreeing with Luke's comment above, if you know the weeks included in the search, can you just push your results onto a pre-filled week->result Map of some type initialized to zero?
A quick google shows this smarter than me guy likes this answer too:
http://thenullreference.com/blog/analytical-queries-using-entity-framework-over-date-ranges-using-linq/

How does NOW/DAY in a Solr query work?

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

Resources