Examine multiple fields search using 'and' and 'or'

A lot has changed in Umbraco 8 compared to Umbraco 7, one of the significant changes in using Examine, in V7 everything was done in Examine config files, in V8, it's all done in C#.

When searching through the documentation as of 12 Jul 2019 the is nothing about how to search multiple fields, so in this example, I will show you how to do it.

To add a twist, I am only searching on doctypes below the parent. 

Search Form

In the form below, I am only searching on doctypes below the parent 'ParentId'

<div class="contact-clean">
        <form action="@Model.Url" method="GET" id="search">
            <div class="form-group">
                <div class="row">
                    <div class="col-xs-12 col-sm-8">
                        <input type="text" class="form-control col-xs-6" placeholder="Search..." name="q" value="@searchQuery" />
                    <div class="col-xs-12 col-sm-4">
                        <button class="btn btn-primary">Search <i class="fa fa-search"></i></button>
                    <div class="col-xs-12">
                        @if (!string.IsNullOrWhiteSpace(searchQuery))
                            if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
                                var searcher = index.GetSearcher();
                                var textFields = new[] { "header", "bodyText" };
                                var results = searcher.CreateQuery("content").ParentId(parentId).And().GroupedOr(textFields, searchQuery).Execute();
                                long resultCount = results != null &&&& results.Any() ? results.Count() : 0;
                                    <p>Found <strong>@resultCount</strong> result@(resultCount != 1 ? "s" : "") when searching for <strong>@searchQuery</strong></p>
                                        @foreach (var result in results)
                                            if (result.Id != null)
                                                var node = Umbraco.Content(result.Id);
                                                    @node.Value("header")<br />
                                <p>Do whatever</p>


As you can now see when searching for 'from', the search returns two results.

search results

I hope you found this quick blog helpful.