Razor syntax for search

@inherits umbraco.MacroEngines.DynamicNodeContext
@using Examine
@using Examine.SearchCriteria
        var searchTerm = "Client";
        if (searchTerm == null)
               <p>Please use the search box</p>

        var searcher = ExamineManager.Instance.SearchProviderCollection[0];
        var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
        var query = searchCriteria.GroupedOr(new string[] { "nodeName", "bodyText" }, searchTerm).Compile();
        var searchResults = searcher.Search(query);
        var noResults = searchResults.Count();

        You searched for @searchTerm, and found @noResults results
        <ul class="search-results">
        @foreach (var result in searchResults)
                <a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["nodeName"]</a>
        <a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["nodeName"]</a>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s