It's quite likely due to the way Examine indexes and compares the fields - effectively, when you compare numeric ranges, you must format them as a string with leading zeros so that the length (number of characters) is identical. This is because Lucene (which Examine is based on) index sorting is done lexicographically. See http://stackoverflow.com/a/6810681/2843504 for an explanation.
So what you probably want to do, is format your prices like this:
Price searching
How do I get this to work for price searching I have followed the demo at:
https://github.com/base33/LinqToExamine-Demo
and have changed to date from - to fields to price and trying to search on :
PriceFrom = 180000 - PriceTo = 200000
But just receiving this error:
Encountered " "TO" "TO "" at line 1, column 36. Was expecting one of:
can you please advise.
Hi Andrew,
I haven't been able to check, but is there a IsWithinRange method or something along them lines on the decimal?
I think it might be an extension. If not, I'll add it in
Thanks!
Craig
Hi Craig,
Thanks for coming back it has to be int values to work anyway so managed to get to working but have strange result:
Updated Models:
Added the following prices: Price 29950 200000 250000
Yet when performing a search and setting the PriceFrom = 200000 for some reason 29950 is included in the results??
Can you advise on this please.
Hi Andrew,
It's quite likely due to the way Examine indexes and compares the fields - effectively, when you compare numeric ranges, you must format them as a string with leading zeros so that the length (number of characters) is identical. This is because Lucene (which Examine is based on) index sorting is done lexicographically. See http://stackoverflow.com/a/6810681/2843504 for an explanation.
So what you probably want to do, is format your prices like this:
Hope this helps!
Rob.
Hi Robert,
Thanks for coming back to me afraid it wont allow me to compare strings this way however I was aware that padding needs to be applied I am using:
And have tried various implementations :
query.And().Range("price", model.MinPrice.ToString("00000000"), model.MaxPrice.ToString("00000000"));
no results
no results
results but including lower values that shouldnt be there, what am I missing do I need to pad the price value somehow?
is working on a reply...