Copied to clipboard

Flag this post as spam?

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


  • David Conlisk 432 posts 1008 karma points
    Jun 16, 2013 @ 19:11
    David Conlisk
    0

    Making a custom field sortable in Examine

    Hi all,

    I am adding custom fields to my Examine index - this works fine. However, I can't seem to sort by my custom fields properly. If they were being defined in the ExamineIndex.config file I would add  EnableSorting="true" - how can I do this in my code? Here is my code (below). I want to then sort by last name, followed by first name.

    Cheers!

    David

    private void indexer_GatheringContactNodeDate(object sender, IndexingNodeDataEventArgs e)
            {
                var fullName = e.Fields["fullName"];
    
                if (e.Fields.ContainsKey("firstName"))
                {
                    e.Fields["firstName"] = fullName.Substring(0, fullName.LastIndexOf(' '));
                }
                else
                {
                    e.Fields.Add("firstName", fullName.Substring(0, fullName.LastIndexOf(' ')));
                }
    
                if (e.Fields.ContainsKey("lastName"))
                {
                    e.Fields["lastName"] = fullName.Substring(fullName.LastIndexOf(' ') + 1);
                }
                else
                {
                    e.Fields.Add("lastName", fullName.Substring(fullName.LastIndexOf(' ') + 1));
                }
            }
  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jun 17, 2013 @ 11:31
    Ismail Mayat
    101

    Dave,

    Checkout http://thecogworks.co.uk/blog/posts/2013/april/examiness-hints-and-tips-from-the-trenches-part-10-document-writing-redux/ there is some code there which will do exactly what you need.

    Regards

    Ismail

  • David Conlisk 432 posts 1008 karma points
    Jun 25, 2013 @ 13:27
    David Conlisk
    0

    Awesome! Works a treat, thanks Ismail! #h5yr

Please Sign in or register to post replies

Write your reply to:

Draft