I have a news article document type which has an dateAuthored datepicker property.
I'm experiencing some strange behaviour with the Range filter in Examine. I'm building up a query which searches my news articles. I'm trying to filter by year by using the following code:
int year = 2014;
DateTime yearDate = new DateTime(year, 1, 1);
query = query.And().Range("dateAuthored", yearDate, yearDate.AddYears(1));
What I have found is that if I set "year" to 2014, all of the 2015 news articles are returned. If "year" is 2013, all 2014 items are returned, if I set it to 2012, all 2013 items return and so on and so on.
Is this the expected behaviour for .Range? Seems like a bug to me.
Hi I had the same thing with a predicate builder for sitecore using solr. My problem was trying to do a query on with .addyears() What I needed to do, was instance a new DateTime object with added years, and then pass that to my query.
Ok so you could remove the range and just use And(date1 < date2) :). Where date1 would be start of 2014 and date2 would be start of 2015 if that makes sense
Yeah I'm not sure what you're talking about exists. :) I mean I can execute the search, and then filter out the results by year with Linq easy enough, but I'd prefer to do it with lucene/examine.
OK son I don't trust .Range() in this circumstance especially with the inconsistencies in index date formatting. Since at the end of the day I only want to filter on year and not on a specific date range I've opted to use RawQuery instead.
Just using RawQuery to check if the value starts with my chosen year. That way it should still work even if a future Umbraco update changes the DatePicker formatting in the index to match createdDate.
Yea it's not the way the date is stored. I have had the exact same issue with predicate builder for Sitecore. Glad you got it fixed. Beowulf be interesting to know what it is doing with the Range(). What are the parameters?
Strange Examine query Range behaviour
Hi folks,
I have a news article document type which has an dateAuthored datepicker property.
I'm experiencing some strange behaviour with the Range filter in Examine. I'm building up a query which searches my news articles. I'm trying to filter by year by using the following code:
What I have found is that if I set "year" to 2014, all of the 2015 news articles are returned. If "year" is 2013, all 2014 items are returned, if I set it to 2012, all 2013 items return and so on and so on.
Is this the expected behaviour for .Range? Seems like a bug to me.
thanks
Hi I had the same thing with a predicate builder for sitecore using solr. My problem was trying to do a query on with .addyears() What I needed to do, was instance a new DateTime object with added years, and then pass that to my query.
Charlie :)
Cheers for your reply! But unfortunately that's not the case in my situation. (as much as I really wanted it to be!)
I just tried the following with the same result:
Can you paste the whole query please :) what happens if you switch the date parameters?
What's more, if I change my "toDate" to 31/12/year (difference of one day) instead I get no results at all. What the heck.
Ok so you could remove the range and just use And(date1 < date2) :). Where date1 would be start of 2014 and date2 would be start of 2015 if that makes sense
Not sure I get what you mean; And() doesn't accept any parameters.
Sorry I got the syntax wrong. I meant you should be able to a conditional check with out the range? Would that help?
Yeah I'm not sure what you're talking about exists. :) I mean I can execute the search, and then filter out the results by year with Linq easy enough, but I'd prefer to do it with lucene/examine.
I wonder if this is a bug with how DatePicker dates are stored/indexed.
Looking in my ExternalIndex with Luke I can see that the Umbraco default propery "createDate" is indexed like this: 20150529004820000
But, my "dateAuthored" datepicker property is indexed like this: 2014-08-18T00:00:00
OK son I don't trust .Range() in this circumstance especially with the inconsistencies in index date formatting. Since at the end of the day I only want to filter on year and not on a specific date range I've opted to use RawQuery instead.
Just using RawQuery to check if the value starts with my chosen year. That way it should still work even if a future Umbraco update changes the DatePicker formatting in the index to match createdDate.
Yea it's not the way the date is stored. I have had the exact same issue with predicate builder for Sitecore. Glad you got it fixed. Beowulf be interesting to know what it is doing with the Range(). What are the parameters?
https://our.umbraco.org/forum/using/ui-questions/16888-Examine-Search-Range-Values Not sure if that irk sheds anymore light :)
I've come across similar odd behaviour. In my case, the following StackOverflow answer provided the clue: http://stackoverflow.com/a/1644592/1944
So what I did to solve the problem was convert my dates into SortableDateTimePattern (i.e.,
.ToString("s")
. Here's a snippet of my code:This sorted out the weird date behaviour nicely.
is working on a reply...