Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 07:52
    Robert Foster
    0

    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:

    +((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...

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jun 18, 2015 @ 08:18
    Ismail Mayat
    0

    Robert,

    Which analyser are you using? Also does the search work with luke?

    Regards

    Ismail

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 08:24
    Robert Foster
    0

    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:

    <add Name="listPrice" Type="Numeric" EnableSorting="true" />
    

    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.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 08:32
    Robert Foster
    0

    Using Luke and running the first query returns 20 results as expected.

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 08:58
    Robert Foster
    0

    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.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jun 18, 2015 @ 09:02
    Ismail Mayat
    0

    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

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 10:05
    Robert Foster
    0

    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

    +(listPrice:[2.5 TO 5])
    

    then I still get all records, including items matching 12.5, 20, 10, 4, 1, ...

    enter image description here

    The field in the index looks like this (I was expecting it to have the Numeric flag):

    enter image description here

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jun 18, 2015 @ 11:08
    Ismail Mayat
    100

    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

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 11:31
    Robert Foster
    0

    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...

  • Robert Foster 459 posts 1820 karma points MVP 3x admin c-trib
    Jun 18, 2015 @ 12:06
    Robert Foster
    0

    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!

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Jun 18, 2015 @ 13:15
    Ismail Mayat
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft