Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
We used to add some rewritten values to the Examine Index to query it with Examine.
For example a datetime picker with name "date" we used to save to index as "dateRewritten" with the correct format to order it and query with ranges like this:
And().Range("dateRewritten", dateFrom, dateTo)
Now in Umbraco 8 we managed to get the dateRewritten correctly in the index, with _TransformingIndexValues event.
But when we now try to query on this field, and use .RangeQuery, we need to pass non nullable type, like long (we save ticks), but then an exception pops up:
: 'Could not perform a range query on the field dateRewritten, it's value type is Examine.LuceneEngine.Indexing.FullTextType'
Is there any way to do a RangeQuery on string field, like it was possible in U7?
How are you manipulating your "dateRewritten" field?
You will need to change it's type to a long in the index so you can do the range, this is the same as what was happening in v7 as you can't do range on text.
Assuming you are using the External Index you can do the following:
var externalIndex = examineManager.Indexes.FirstOrDefault(i=>i.Name == "ExternalIndex");
if(externalIndex != null)
externalIndex.FieldDefinitionCollection.AddOrUpdate(new FiledDefinition("dateRewritten", FieldDefinitionTypes.Long));
This can then be used to perform a ranged query against once you've populated it with the ticks value for the given date.
can you give a simple example to full code that searches using examine between tow dates?
because I can't find .Indexes in ExamineManager
and want to see in which way would I use the examine to make this code working well
Are you using Umbraco v7 or Umbraco v8?
I am using v8
Have a read of my blog post about it: https://justnik.me/blog/indexing-sort-able-dates-in-umbraco-version-8
It doesn't have an example of the searching side of it, but it's the indexing that is the bigger issue. I'll see if I dig out some example code of doing the search for you.
I have read this article before and tried to write that code in my project but I faced a problems with sorting indexes something like wasting the sort of index but let me know when you dig out some example code of doing the search
ok this one was helpful actually, thanks
This was where I was looking for, thank you!
I had the same issue with Umbraco 8.
Once I added my custom field I had to add int rather than long.
Here is My code to create the custom index set.
e.Index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition(alias, FieldDefinitionTypes.Integer));
Here is my code for the range search.
examineQuery.And().RangeQuery<int>(fields, 2, 10, true);
Thinking about it now I am assuming I could change my range query to long and then Nik's example would probably work for me too. I haven't tested this yet through.
examineQuery.And().RangeQuery<long>(fields, 2, 10, true);
Hope this helps someone.
It might also be useful to post this here.
Here is an example of an Examine date RangeQuery.
Here is the ValueSet I added.
e.Index.FieldDefinitionCollection.AddOrUpdate(new FieldDefinition("comparableDate", FieldDefinitionTypes.DateTime));
And here is the Examine query
examineQuery.And().RangeQuery<DateTime>(fields, DateTime.MinValue, DateTime.Now);
In umbraco 9 you can configure it as following:
public sealed class ConfigureCustomIndexOptions : IPostConfigureOptions<LuceneDirectoryIndexOptions>
public void PostConfigure(string name, LuceneDirectoryIndexOptions options)
and you should register the configuration in startup
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted