Copied to clipboard

Flag this post as spam?

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


  • Ayo Adesina 419 posts 1001 karma points
    Feb 24, 2015 @ 15:09
    Ayo Adesina
    0

    Umbraco Search - How do I tell what doc type a search result is?

    I am using umbraco search / lucene in my project and I am getting the results I want.

    but I want to treat search results that are of a certain doc type differently, how do I determine a doc type from search results?

    Heres what I have so far.

    var Searcher = Examine.ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
    var searchCriteria = Searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
    var query = searchCriteria.Field("nodeName", q.Boost(3)).Or().Field("description", q.Boost(3)).Or().Field("bodyText", q.Fuzzy()).Or().Field("content", q.Boost(3));
    
    var searchResults = Searcher.Search(query.Compile()).OrderByDescending(x => x.Score).TakeWhile(x => x.Score > 0.05f);
    
     @foreach (var item in searchResults)
              {
                  //if item is doc type... bla bla bla
               }
    
  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Feb 24, 2015 @ 15:23
    Jan Skovgaard
    0

    Hi Ayo

    According to the Razor cheat sheet https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets you should be able to simply do item.DocumentTypeAlias === "youralias" - You might need to cast it as a string though so perhaps item.DocumentTypeAlias.ToString() === "youralias" is better.

    Does that work?

    /Jan

  • 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