I'm trying to perform a grouped range search on a price field, and have crafted the following query:
+((listPrice:[2.5 TO 5]) (listPrice:[20 TO 25]))
(I've stripped out less relevant fields for this example - this is the bit that is playing up). The default Boolean is AND.
When I run this through the Searcher in code, I get no results; however running the exact same query through the Examine Manager in the Developer section using Lucene Search; I get the expected results.
Any ideas why this might be happening?
Another oddity: If I set up the range so that the upper bound is non-inclusive (use } instead of ]) I get the following error:
+((listPrice:[2.5 TO 5}) (listPrice:[20 TO 25}))
Failed to search
Encountered "
at Lucene.Net.QueryParsers.QueryParser.Jjconsumetoken(Int32 kind)
at Lucene.Net.QueryParsers.QueryParser.Term(String field)
at Lucene.Net.QueryParsers.QueryParser.Clause(String field)
at Lucene.Net.QueryParsers.QueryParser.Query(String field)
at Lucene.Net.QueryParsers.QueryParser.Clause(String field)
at Lucene.Net.QueryParsers.QueryParser.Query(String field)
at Lucene.Net.QueryParsers.QueryParser.Clause(String field)
at Lucene.Net.QueryParsers.QueryParser.Query(String field)
at Lucene.Net.QueryParsers.QueryParser.TopLevelQuery(String field)
at Lucene.Net.QueryParsers.QueryParser.Parse(String query)
although it appears to parse okay when running it through the searcher in the backend...
I haven't specified an Analyzer (maybe that's part of the problem) - this is a custom index with all the necessary fields. The index User Field looks like this:
I suspect part of my problem is that the field is not being indexed as a numeric. Changing the field definition from Numeric to DOUBLE makes no difference to the index; still stores the value as string and doesn't flag it as a numeric field.
In your config for the custom index can you see what analyser you are using. Then try using that analyser in luke and see if you still get results.
Also can you send screen grab of what the numeric fields look like in luke, do a search get results and click on one of the results that will give you detailed information window.
Hi Ismail,
Yes, I was beginning to think I'd need to do that...
The Examine implementation is very misleading given that it offers the methods to do ranged searches on different types of data; we probably need to get this addressed at some stage.
Thanks for your help mate; I should've stopped bashing my head against this hours ago...
Excellent - that worked; although of course I had to convert the doubles to an int (times 100 and cast) before I could apply the .ToString("D6"), but it worked like a charm.
I have always done it this way, I also would have thought marking type in the examine config should get it into the index in the correct format. Lucene does not have concept of types as its all strings/text.
Examine Grouped Range Numeric Search oddities
I'm trying to perform a grouped range search on a price field, and have crafted the following query:
(I've stripped out less relevant fields for this example - this is the bit that is playing up). The default Boolean is AND.
When I run this through the Searcher in code, I get no results; however running the exact same query through the Examine Manager in the Developer section using Lucene Search; I get the expected results.
Any ideas why this might be happening?
Another oddity: If I set up the range so that the upper bound is non-inclusive (use } instead of ]) I get the following error:
although it appears to parse okay when running it through the searcher in the backend...
Robert,
Which analyser are you using? Also does the search work with luke?
Regards
Ismail
I haven't specified an Analyzer (maybe that's part of the problem) - this is a custom index with all the necessary fields. The index User Field looks like this:
I'd originally had the type set to "Double" but that didn't work (a value of 4 wasn't matching a range of 2.5 TO 25), so changed it to Numeric;
I haven't looked at it in Luke as yet; will have to go find it and see.
Using Luke and running the first query returns 20 results as expected.
I suspect part of my problem is that the field is not being indexed as a numeric. Changing the field definition from Numeric to DOUBLE makes no difference to the index; still stores the value as string and doesn't flag it as a numeric field.
Robert,
In your config for the custom index can you see what analyser you are using. Then try using that analyser in luke and see if you still get results.
Also can you send screen grab of what the numeric fields look like in luke, do a search get results and click on one of the results that will give you detailed information window.
Regards
Ismail
The analyzer is the Standard Lucene one; and I've just realised that the above query in Luke is returning all records.
If I shorten the query to
then I still get all records, including items matching 12.5, 20, 10, 4, 1, ...
The field in the index looks like this (I was expecting it to have the Numeric flag):
Robert,
In the past doing range searches i have always had to fudge the data slightly using gatheringnode data event.
See this uhangout vid https://www.youtube.com/watch?t=1460&v=DyEeAe0WV6Y on how i did http://www.thefabricofindustry.com/ I do numeric range searches.
So I always format numerics to D6 so in your case price of 4 would be injected into the index as 000004 see https://our.umbraco.org/forum/developers/extending-umbraco/11819-Examine-range-query-numeric
Regards
Ismail
Hi Ismail, Yes, I was beginning to think I'd need to do that...
The Examine implementation is very misleading given that it offers the methods to do ranged searches on different types of data; we probably need to get this addressed at some stage.
Thanks for your help mate; I should've stopped bashing my head against this hours ago...
Excellent - that worked; although of course I had to convert the doubles to an int (times 100 and cast) before I could apply the .ToString("D6"), but it worked like a charm.
Thanks!
Robert,
I have always done it this way, I also would have thought marking type in the examine config should get it into the index in the correct format. Lucene does not have concept of types as its all strings/text.
Glad you got it working.
Regards
Ismail
is working on a reply...