basically, Lucene cannot compare numeric values at all, it's comparing all values as strings. So to make it work you need to prepare your values before storing them in Examine index. Otherwise, Lucene will see them as strings, so if you, for example, have 1, 11, 50 and 100, the order, using string sort will be:
1
100
11
50
to make them sort as numbers you need to pad them left and bring them to the same format, e.g. 00001, 00011, 00050, 00100. Then when you sort them as strings you will get:
Lucene Search Not Working on range
Hi I have the following code and I cannot get it to work when searching with range.
Can anyone help with this problem, my code is below.
Thanks in advance
hi George, could you extract raw Lucene query you are getting?
The second question, are you padding bidPrice same way in OnGatheringNodeData to keep the same format?
Hi Pawel
Not sure what you mean by return raw query, but I have done this
ISearchCriteria query1 = searchCriteria.Range("bidPrice", paddedLower, paddedHigher, true, true).Compile().RawQuery(q);
Result:
SearchIndexType: "", LuceneQuery: {+bidPrice:[10.00 TO 100.00] +bidPrice:[10.00 TO 100.00] +(id:tack nodeName:tack updateDate:tack writerName:tack nodeTypeAlias:tack description:tack)}
What is 'OnGatheringNodeData' as I have not done that
Regards George
hi George,
basically, Lucene cannot compare numeric values at all, it's comparing all values as strings. So to make it work you need to prepare your values before storing them in Examine index. Otherwise, Lucene will see them as strings, so if you, for example, have 1, 11, 50 and 100, the order, using string sort will be: 1 100 11 50
to make them sort as numbers you need to pad them left and bring them to the same format, e.g. 00001, 00011, 00050, 00100. Then when you sort them as strings you will get:
00001 00011 00050 00100
you can do it like this:
and then:
Hi Pawel
I must be still doing something wrong, I get the following error:
Thanks George
Hi Pawel
I have removed the D6, but now it returns all values that are also outside the range
Also when doing search in backoffice, padding is not added to field
_Icon: icon-shopping-basket color-yellow _IndexType: content _Key: 24fb8acf-9533-43e0-afa7-ad11ac16a8e7 _NodeId: 1075 _NodeTypeAlias: itemsforsale _Path: -1,1056,1073,1075 bidEndDateTime: 2018-03-20T10:00:00 bidPrice: 30.01 description:
Regards
George
ok, so you are using
IndexUserFields
:)if you check https://our.umbraco.org/documentation/reference/config/examinesettings/
you can find this info:
Type is the data type of the field. By default the data type is a string Data types supported are:
try to set:
<add Name="bidPrice" EnableSorting="true" Type="DOUBLE" />
Hi Pawel
Just been checking that, have changed to double and about to test.
Hopefully will work
Regards George
Hi Pawel
Thanks, that now works :)
Regards George
is working on a reply...