0

I need to display a list of items based on their path. For instance:

Content tree setup: enter image description here

I am trying to sort results by item path, so if I perform a search that matches the items in the below list then the results would display in the following order, regardless of relevance, age, etc.:

  • CategoryA
  • Book1
  • Article1
  • CategoryB
  • Book2
  • Article4

I have tried using .OrderBy(x => [SearchReturnedItem].Paths.Path).ToArray(), but it's not working. Does anyone have any suggestions that might help?

edit - code moved to question body

using (var searchContext = ContentSearchManager.GetIndex("<indexname>").CreateSearchCon‌​text()) 
{ 
    var result = searchContext.GetQueryable<SearchResultItem>()
      .Where(x => x.TemplateId.Guid.ToString()
      .Contains("<Template1-GUID>,<Tem‌​plate2-GUID>,<Templa‌​te3-GUID>,..>")); 

    var sortedResult = result.OrderBy(x => x.Path); 
}
  • 2
    Have you tried OrderBy(x => x.Path)? – Marek Musielak Jan 26 '17 at 9:46
2

The [SearchReturnedItem].Paths.Path) is going to to return the list of ItemIDs for the path. You'll want to instead sort by [SearchReturnedItem].Path which will sort by the full text path you are looking for.

  • 1
    Assuming [SearchReturnedItem] is a SearchResultItem then technically [SearchReturnedItem].Paths.Path should result in a compilation error since SearchResultItem.Paths is an IEnumerable<ID>, but you are correct that what the OP is looking for is SearchResultItem.Path :) +1 – Zachary Kniebel Jan 26 '17 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.