For Examine experts!
Have a strange issue with Examine in Umbraco 8. If I use the fluent API to create a RangeQuery using dates then it works, but if I execute the same query as a raw query then it doesn’t. To provide an example:
if (ExamineManager.Instance.TryGetIndex(global::Umbraco.Core.Constants.UmbracoIndexes.ExternalIndexName, out var index))
{
var searcher = index.GetSearcher();
var query = searcher.CreateQuery("content").RangeQuery<DateTime>(new string[] { "createDate" }, DateTime.Now.AddDays(-37), DateTime.Now);
var results = query.Execute();
// results.TotalItemCount = 2;
}
So the above query returns 2 results, which is correct. It just returns items with a create date between the two specified dates, as expected.
However, if I take the raw Lucene query from the above code (eg. via query.ToString()
) I get this:
+(createDate:[637109872908600000 TO 637141840908600000])
(Note the date ticks values will change depending on what the current date is - this is just an example).
Now if I run this in the back-office Examine Management dashboard it returns every node, even if I amend it just to search content. So my query would actually be:
+__IndexType:content +createDate:[637109872908600000 TO 637141840908600000]
This still returns every content node in the site.
In fact, even this query below returns every node when I would expect it to return none (as the ‘from’ date is after the ‘to’ date).
+__IndexType:content +createDate:[999999999999999999 TO 637143565034990000]
I’ve run these queries in the back office Examine Management dashboard and also via Luke.Net to same effect. It’s like the range query is ignored.
So my question is why does the date range query work when constructed via the fluent API, but not if constructed manually as a raw query?
Is there any way to get the raw query to work? (I’m building a rather complex query via a raw Lucence query and it works fine apart from this date range part). Note I’m searching the built-in createDate
field, not a custom field, and I can see the date is being stored as ticks in the index. I’m using the Standard Analyser, too.
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/100637-raw-lucene-date-range-query-not-working-in-examine-umbraco-8