Copied to clipboard

Flag this post as spam?

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


  • Gowtham Kumar A 1 post 71 karma points
    Nov 17, 2023 @ 17:20
    Gowtham Kumar A
    0

    Examine Search - Search result with html content

    I'm currently working on a search functionality, and I'm looking for guidance on how to improve the search results. Currently, the code successfully retrieves pages containing the specified keyword and provides a link to each page. However, I'm keen on augmenting the results by also including relevant sentences or lines containing the search keyword, along with a redirect link to the respective page.

    For instance, if the search term is 'Products,' the desired outcome would be a list of pages containing the keyword, along with snippets or sentences that include the keyword 'Product.' Additionally, each result should be accompanied by a redirect link to the corresponding page.

    The existing code that brings the page which as the keyword and the URL to the page. Could anyone provide insights or modifications to populate the results with along with line or sentences that include the keyword 'Product.'

    ----Current code which is used to populate the page and url------

    @using Examine
    @using Umbraco.Cms.Web.Common
    @inject IExamineManager ExamineManager;
    @model (string searchTerm, UmbracoHelper Umbraco)
    
    <!----> <partial name="Search" model="Model.searchTerm" />
    
    @if (ExamineManager.TryGetIndex("ExternalIndex", out var index))
    {
        var results = index.Searcher.Search(Model.searchTerm);
        if (results?.Any() ?? false)
        {
            <ul>
                @foreach (var result in results)
                {
                    var content = Model.Umbraco.Content(result.Id);
                    <li>
                        <a href="@content?.Url()">@content?.Name</a>
                    </li>
                }
            </ul>
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft