Copied to clipboard

Flag this post as spam?

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


  • sun 403 posts 395 karma points
    Nov 22, 2012 @ 07:57
    sun
    0

    How to sort Examine result and sort it by multiple fields?

    I have set Examine rightly and now I can use it get nodes. But I want to sort node by using multiple user fields, How to do it?

        <IndexSet SetName="SimpleIndexSet" IndexPath="~/App_Data/SimpleIndexSet">

          <IndexUserFields>

            <add Name="Order"  EnableSorting="true" type="Number" />

            <add Name="PublishDate" EnableSorting="true" type="DateTime"/>

          </IndexUserFields>

        </IndexSet>

    the Following is right:

    var searchResults = Searcher.Search(query).OrderByDescending(x => x.Fields["Order"]);

    After I change Order to PublishDate, It shows error. Why this happen?

     

  • sun 403 posts 395 karma points
    Nov 22, 2012 @ 08:00
    sun
    0

    I know I can use:

    var searchResults = Searcher.Search(query).OrderByDescending(x => x.Order).OrderByDescending(x => x.PublishDate);

    But now PublishDate can't be used. Why?

  • Mike Chambers 636 posts 1253 karma points c-trib
    Nov 22, 2012 @ 10:16
    Mike Chambers
    0

    Not entirely sure what you are asking... but

    var searchResults = Searcher.Search(query).OrderByDescending(x => x.Order).OrderByDescending(x => x.PublishDate);

    will only order by publishdate... if you want to order by Order and then publishdate then this should work

    var searchResults = Searcher.Search(query).OrderByDescending(x => x.Order).ThenByDescending(x => x.PublishDate);

     

    or if you are having issues with actually using x.PublishDate then maybe this can be used?

    .ThenByDescending(x => Convert.ToDateTime(x.GetPropertyValue("PublishDate"))

    ??

  • sun 403 posts 395 karma points
    Nov 22, 2012 @ 10:24
    sun
    0

    Thank you! I just wonder why PublishDate can't be used!!! I have added it into SimpleIndexSet.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies