I have an ExamineSearch and having a problem about .Range().
Here is my Code:
var bed = string.IsNullOrEmpty(model.Bed) ? "" : model.Bed;
if (bed == "5")
{
searchQuery.And().Range("bedrooms", Convert.ToInt32(bed), 0);
// This code is no display.
}
else
{
searchQuery.And().Field("bedrooms", bed);
}
I tried also manual input in bedrooms, like this:
searchQuery.And().Range("bedrooms", 5, 0);
// but still no display.
Essentially Examine will index all fields as strings unless directed to otherwise...
you tell it to index as an integer by changing the examine index configuration field eg Adding the bedrooms property to a IndexUserFields section along with Type="INT"...
but... since your bedrooms are likely to be less than 10, you should in theory be able to get the results you need if Examine stores the number of bedrooms as a string! as alphapbetically 0 is before 1 is before 2 etc
Hopefully you understand why it doesn't work, because Examine is storing the bedrooms value as a string and so Range is working 'alphabetically' rather than numerically eg
NOT 1, 2, 3 ..., 8,9,10,11
but
1,10,11,2,3
, so it would only work for small houses!!
You have two options, tell Examine that the bedrooms field is a number, and then range will work numerically.
You can achieve this by adding a 'IndexUserFields' configuration element to your examine index, and adding the 'bedrooms' property, specifying it's type as an INT. (see example above)
or your section option is to use a gathering nodes event to add an additional property to your index, which is the number of bedrooms padded with zeros, to enable them to be compared as strings.
Examine Range not working?
Hi All,
I have an ExamineSearch and having a problem about .Range().
Here is my Code:
I tried also manual input in bedrooms, like this:
Any ideas!
Thanks,
Jin
Hi Jin
What 'type' is bedrooms in your examine configuration, eg is it being indexed as an integer:
(you will need to rebuild your indexes if you change this configuration, in /config/examineindex.config - see https://github.com/Shazwazza/Examine/wiki/IndexSet for more info)
The Range filter in Examine has the signature
public IBooleanOperation Range(string fieldName, int start, int end)
So I wonder if you need to have the numbers around the other way
eg
searchQuery.And().Range("bedrooms", 0, 5);
Hi Marc,
Sorry but I'm not the one created this Examine, but these all I got,
Can you refer it here? https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/93375-examineindexes-not-working-properly
It was all answered by Dave but I have little problem regarding .Range in bedrooms...
Cheers,
Jin
Hi Jin
Yes maybe Dave will answer on that thread too!
Essentially Examine will index all fields as strings unless directed to otherwise...
you tell it to index as an integer by changing the examine index configuration field eg Adding the bedrooms property to a IndexUserFields section along with Type="INT"...
but... since your bedrooms are likely to be less than 10, you should in theory be able to get the results you need if Examine stores the number of bedrooms as a string! as alphapbetically 0 is before 1 is before 2 etc
So do perhaps try
searchQuery.And().Range("bedrooms", "0", "5");
regards
Marc
Hi Marc,
Yes, I am waiting for Dave's answer.
This code works, but not display the right products.
It's showing the products with 1 bedroom, 4 bedrooms, 5 bedrooms, and also the 11 bedrooms?
But All I need is equal more than 5 bedrooms ( >= 5 )
Thanks,
Jin
Hi Jin
yes Dave is ace!
Hopefully you understand why it doesn't work, because Examine is storing the bedrooms value as a string and so Range is working 'alphabetically' rather than numerically eg
NOT 1, 2, 3 ..., 8,9,10,11
but
1,10,11,2,3
, so it would only work for small houses!!
You have two options, tell Examine that the bedrooms field is a number, and then range will work numerically.
You can achieve this by adding a 'IndexUserFields' configuration element to your examine index, and adding the 'bedrooms' property, specifying it's type as an INT. (see example above)
or your section option is to use a gathering nodes event to add an additional property to your index, which is the number of bedrooms padded with zeros, to enable them to be compared as strings.
There is a thread that discusses this approach here: https://our.umbraco.com/forum/developers/extending-umbraco/11819-Examine-range-query-numeric
is working on a reply...