As my title suggests, I am wanting my search code to omit anything in my media folder. Right now, if I search for "test" it will bring back any page with the word test in it as well as any document or image which has test on it as well.

Is there a way I can amend my current search code to do this?

My code looks like this. Please note I have removed my pagination code as it wasn't applicable to my issue:

@{
    Layout = "Master.cshtml";
    @*search variables*@
    var searchTerm = Request["term"];

    if (String.IsNullOrEmpty(searchTerm))
    {
        <p>Please use the search box</p>
        return;
    }


    @*the searcher instance to use - Umbraco has 3 by default - InternalSearcher, ExternalSearcher and InternalMemberSearcher *@
    var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
    var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
    @* define node properties to be searched below *@
    var query = searchCriteria.GroupedOr(new string[] { "pageTitle", "metaDescription", "nodeName", "heading", "bodyText", "summary" }, searchTerm.Fuzzy(0.5f)).Compile();

    var searchResults = searcher.Search(query);
    var resultPage = searchResults.Skip(currentPage * itemsPerPage).Take(itemsPerPage);
    var noResults = searchResults.Count();
    var numberOfPages = Math.Ceiling((decimal)((noResults - 1) / itemsPerPage)) + 1;
    var pages = Enumerable.Range(1, (int)numberOfPages);
}

@Html.Partial("Breadcrumb")

<div class="container content">
    <h3>You searched for <b>@searchTerm</b>, we found @noResults results</h3>

    <ul class="row clearfix list-unstyled newslist">
        @foreach (var result in resultPage)
        {
            <li class="col-md-12 column">
                <div class="row clearfix">
                    <div class="col-md-12 column">

                        <h2>
                            @if (result.Fields.ContainsKey("pageTitle"))
                            {
                                <a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["pageTitle"]</a>
                            }
                            else
                            {
                                <a href="@umbraco.library.NiceUrl(result.Id)">@result.Fields["nodeName"]</a>
                            }

                        </h2>

                        @if (result.Fields.ContainsKey("metaDescription"))
                        {
                            <p>
                                @result.Fields["metaDescription"]
                            </p>
                        }

                        @if (result.Fields.ContainsKey("summary"))
                        {

                            <p>
                                @result.Fields["summary"]

                            </p>
                        }

                        @*@foreach(var fieldItem in result.Fields)
                            {
                                <p>@fieldItem.Key <b>: </b> @fieldItem.Value</p>
                            }*@

                        <p class="pull-left">
                        </p><div class="addthis_sharing_toolbox"></div>
                        <p></p>

                        <p class="pull-right">
                            <a class="btn btn-green" href="@umbraco.library.NiceUrl(result.Id)">View details ยป</a>
                        </p>
                    </div>
                </div>
            </li>
        }
    </ul>
</div>

Related posts

Recent Viewed