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

Umbraco 8.0.2

A lot has changed in Umbraco 8 compared to Umbraco 7, one of the big changes in using Examine, in V7 everything was done in Examine config files, in V8, its 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>
                    <div class="col-xs-12 col-sm-4">
                        <button class="btn btn-primary">Search <i class="fa fa-search"></i></button>
                    </div>
                    <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>
                                    <ul>
                                        @foreach (var result in results)
                                        {
                                            if (result.Id != null)
                                            {
                                                var node = Umbraco.Content(result.Id);
                                                <li>
                                                    @node.Value("header")<br />
                                                    @node.Value("bodyText")
                                                </li>
                                            }
                                        }
                                    </ul>
                            }
                            else
                            {
                                <p>Do whatever</p>
                            }
                        }
                    </div>
                </div>
            </div>
        </form>
    </div>

Examine multiple fields search and or

Blog Form

 Please complete the required fields (*required)

 *
*