Imagine being paid to improve your favorite CMS!

It could be you! Umbraco HQ are hiring and are looking for both talents and senior developers. Wonderful workplace, friendly colleagues and competitive salary.

Copied to clipboard

Flag this post as spam?

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


  • blackhawk 206 posts 964 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 545 posts 3282 karma points mvp 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 206 posts 964 karma points
    5 days ago
    blackhawk
    0

    Thank you! This works for me.

Please Sign in or register to post replies

Write your reply to:

Draft