Copied to clipboard

Flag this post as spam?

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


  • blackhawk 313 posts 1368 karma points
    Jul 02, 2017 @ 02:12
    blackhawk
    0

    examine custom sort results based on integer

    I would like to accomplish the following and simply would like to know if it's possible through Umbraco 7.

    (1) Attach a custom property editor to each content node that holds a custom integer ranging from 1 to 100.

    (2) Through examine search results, sort results in ascending order based on that integer value.

    is this possible?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Jul 02, 2017 @ 09:49
    Marc Goodson
    100

    Hi blackhawk

    Yes, have a look at the examine documentation for sorting here:

    https://github.com/Shazwazza/Examine/wiki/Sorting-results

    Essentially examine will sort by string by default, eg return "10" before "2" for a numerical field, but if you tell it via the examine configuration that the index item is of type INT, and enablesorting on it, (same for datetime too) then you should be able to achieve the result you are after.

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

    and query

    var sc = ExamineManager.Instance.CreateSearchCriteria();
    
    var query = sc.Field("doc", "hats")
         .And()
         .OrderBy("likes[Type=INT]");
    

    regards

    Marc

  • blackhawk 313 posts 1368 karma points
    Oct 11, 2017 @ 17:29
    blackhawk
    0

    Thank you! This works for me.

Please Sign in or register to post replies

Write your reply to:

Draft