Copied to clipboard

Flag this post as spam?

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


  • Antoinette Silago 21 posts 92 karma points notactivated
    Dec 12, 2018 @ 20:13
    Antoinette Silago
    0

    Content Search Issue with Archetype

    We are using Umbraco for our company website and noticed an issue when using Archetype within the content. When you set content using Archetype to be disabled, it will still show up in your search. Is there an easy way to get the field sets from Archetype so the disable content will not show up in your search?

  • Antoinette Silago 21 posts 92 karma points notactivated
    Dec 12, 2018 @ 20:15
    Antoinette Silago
    0

    The code we are using for search

    @{ var searchTerm = Request.QueryString["q"];

    if (string.IsNullOrWhiteSpace(searchTerm))
    {
        searchTerm = "";
    }
    
    var searcher = ExamineManager.Instance;
    var searchCriteria = searcher.CreateSearchCriteria();
    var query = searchCriteria.GroupedOr(new[] { "nodeName", "contentModules", "eventName", "eventShortDescription", "pagePromoTitle", "pagePromoTagline", "pagePromoDescription", "navTitle", "breadcrumbTitle", "htmlTitle", "metaKeywords", "metaDescription", "hideFromSearch", "Disabled"}, searchTerm).Not().Field("hideFromSearch","1").Not().Field("Disabled","1").Compile();   
    var searchResults = searcher.Search(query).Where(r => r["__IndexType"] == "content").ToList();  
    

    }

    Search Results for @searchTerm

    @Html.Partial("Includes/siteSearch", Model.Content)

    @if (searchResults.Any()) {

      @foreach (var result in searchResults) { var node = Umbraco.TypedContent(result.Id); var pathIds = result["__Path"].Split(','); var path = Umbraco.TypedContent(pathIds).Where(p => p != null).Select(p=> new {p.Name}).ToList();

              <li>
                  <section class="results-box">                               
      
                  <p>
                      <a href="@node.Url" class="results-url">@node.Name</a><br/>
                      <small>@string.Join(" > ", path.Select(p => p.Name))</small>
                  </p>                            
      
                  @if (result.Fields.ContainsKey("title"))
                  {
                      <p class="results-title"><strong>@result["title"]</strong></p>
                  }
      
                  @if (result.Fields.ContainsKey("metaDescription"))
                  {
                      <p>@result["metaDescription"].Truncate(250)</p>
                  }                                   
      
                  </section>
              </li>
          }
      </ul>
      

      } else {

      There are no results matching your search criteria:

              @if (!string.IsNullOrWhiteSpace(searchTerm))
              {
                  <text>'@searchTerm'</text>
              }
      </p>
      

      }

  • Marcio Goularte 374 posts 1346 karma points
    Dec 12, 2018 @ 20:30
    Marcio Goularte
    100

    Hi Antoinette,

    You need to index the Archetype content. This is done by implementing the GatheringNodeData of the index you want.

    Here are some examples. One of them is from Kevin Creator of Archetype .

    http://nathanw.com.au/blog/indexing-archetype-content-in-umbraco/

    Kevin sample https://gist.github.com/kgiszewski/aa48da36733aa05e1acddd167da2b99a

    video of Kevin on Youtube

    https://www.youtube.com/watch?v=526X0B_sqFw

  • Antoinette Silago 21 posts 92 karma points notactivated
    Dec 12, 2018 @ 23:04
    Antoinette Silago
    1

    Thank you.

Please Sign in or register to post replies

Write your reply to:

Draft