Copied to clipboard

Flag this post as spam?

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


  • MBE 244 posts 845 karma points
    Mar 19, 2017 @ 08:49
    MBE
    0

    Examine search - Combine parent node name with product title

    Greetings,

    I'm trying my luck another time guys and ask you if you can help me figure this out.

    Video demonstration

    First of all, I recorded a video to demostrate my problem here, i find that easier than typing it :)

    https://youtu.be/kOmTi9yDYVw

    Text description

    1. If I search for Epic that bike will be displayed becaues it has the title Epic

    2. If I however make a search for Specialized that Epic bike will not be displayed because the word Specialized isn't in the product title.

    3. The word Specialized is the parent, parent node

    enter image description here

    ExamineIndex.config

          <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/ExamineIndexes/External/">
    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName"/>
      <add Name="updateDate" />
      <add Name="writerName" />
      <add Name="nodeTypeAlias" />
    </IndexAttributeFields>
    <IndexUserFields>
      <!--<add Name="bodyText"/>-->
      <add Name="siteName"/>
      <add Name="year"/>
      <add Name="price"/>
      <add Name="genderList"/>
      <add Name="productImages"/>
    </IndexUserFields>
    <IncludeNodeTypes>
      <add Name="productPage" />
    </IncludeNodeTypes>
    

    Search.cshtml

           var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
    var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
    
    var query = searchCriteria.GroupedOr(new string[] { "nodeName" }, searchTerm).Compile();
    List<Examine.SearchResult> searchResults = searcher.Search(searchTerm, useWildcards: true).ToList();
    searchResults = searchResults.OrderBy(x => x.Fields["nodeName"]).ToList();
    var noResults = searchResults.Count();
    
    <h1 class="section-headline">
        <span>Søgning</span>
    </h1>
    
    <div class="container searchPage">
        <div>
            <p>
                Du søgte efter <strong>@searchTerm</strong>, vi fandt @noResults resultater. <br />
            </p>
        </div>
        <div id="categoryCollection">
    
            @foreach (var result in searchResults)
            {
                IPublishedContent node = new UmbracoHelper(UmbracoContext.Current).TypedContent(result.Fields["id"].ToString());
                IPublishedContent parentNode = node.Parent.Parent;
    
                <article class="product">
                    <a href="@umbraco.library.NiceUrl(result.Id)">
                        @{
                            var imageIds = result.Fields["productImages"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                            var images = Umbraco.Media(imageIds);
                            var firstImage = images.FirstOrDefault();
                            var firstImageUrl = firstImage.Url;
                        }
    
                        <div class="categoryImageCollection">
                            <div class="categoryImage">
                                <img src="/ImageGen.ashx?image=@firstImageUrl&width=150" />
                            </div>
                        </div>
    
                        <span class="model">
                            @parentNode.Name @result.Fields["nodeName"]
                        </span>
                        <div class="price">
                            @result.Fields["price"];
                        </div>
                    </a>
                </article>
                                }
        </div>
    </div>
    
  • 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