Using RangeQuery on custom (string) fields (Umbraco 8)
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.
Hi Nik
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
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
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.
Using RangeQuery on custom (string) fields (Umbraco 8)
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?
Hey Remko,
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.
Thanks
Nik
Assuming you are using the External Index you can do the following:
This can then be used to perform a ranged query against once you've populated it with the ticks value for the given date.
Nik
Hi Nik 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
Hi Mus'ab,
Are you using Umbraco v7 or Umbraco v8?
Cheers
Nik
Hi Nik
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.
Hi Nik
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!
Hi,
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.
Here is my code for the range search.
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.
Hope this helps someone.
Regards
David
Hi All,
It might also be useful to post this here.
Here is an example of an Examine date RangeQuery.
Here is the ValueSet I added.
And here is the Examine query
Hope this helps someone.
Regards
David
In umbraco 9 you can configure it as following:
and you should register the configuration in startup
Did it work for your a search with
RangeQuery
withDateTime
in Umbraco 9?Because for me it does not return any results in Umbraco 10: https://our.umbraco.com/forum/using-umbraco-and-getting-started/110864-examine-searchs-rangequerydatetime-not-returning-any-results
If anyone needs the documentation for version 10+, it is here: https://docs.umbraco.com/v/10.x-lts/umbraco-cms/reference/searching/examine/indexing
Although currently
RangeQuery<DateTime>
is not working for me... not sure about other field types.is working on a reply...