Copied to clipboard

Flag this post as spam?

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


  • Jin Botol 134 posts 287 karma points
    Aug 23, 2018 @ 07:26
    Jin Botol
    0

    Examine Range not working?

    Hi All,

    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.
    

    Any ideas!

    Thanks,

    Jin

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 23, 2018 @ 08:03
    Marc Goodson
    1

    Hi Jin

    What 'type' is bedrooms in your examine configuration, eg is it being indexed as an integer:

    <ExamineLuceneIndexSets>
      <IndexSet SetName="documentationIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/documentation/">
        <IndexUserFields>
          <add Name="doc"/>
          <add Name="bedrooms" Type="INT" EnableSorting="true"/>
        </IndexUserFields>
      </IndexSet>
    </ExamineLuceneIndexSets>
    

    (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);

  • Jin Botol 134 posts 287 karma points
    Aug 23, 2018 @ 08:13
    Jin Botol
    0

    Hi Marc,

    Sorry but I'm not the one created this Examine, but these all I got,

    <ExamineLuceneIndexSets>
      <IndexSet SetName="InternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Internal/"/>
    
      <IndexSet SetName="InternalMemberIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/InternalMember/">
        <IndexAttributeFields>
          <add Name="id" />
          <add Name="nodeName"/>
          <add Name="updateDate" />
          <add Name="writerName" />
          <add Name="loginName" />
          <add Name="email" />
          <add Name="nodeTypeAlias" />
        </IndexAttributeFields>
      </IndexSet>
    
      <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" />
    </ExamineLuceneIndexSets>
    

    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

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 23, 2018 @ 09:37
    Marc Goodson
    0

    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

  • Jin Botol 134 posts 287 karma points
    Aug 24, 2018 @ 02:44
    Jin Botol
    0

    Hi Marc,

    Yes, I am waiting for Dave's answer.

    This code works, but not display the right products.

    searchQuery.And().Range("bedrooms", "0", "5");

    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

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 25, 2018 @ 12:31
    Marc Goodson
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft