Quantcast
Channel: ActiveTopics
Viewing all articles
Browse latest Browse all 72689

Search query not pulling through the right results

$
0
0

I'm trying to set up a site search and a blog search. Currently for the site search I have:

if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
                {
                    var searcher = index.GetSearcher();
                    var searchResults = searcher.Search(searchTerm);
                    if (searchResults.Any())
                    {
                        <ul>
                            @foreach (var result in searchResults)
                            {
                                if (result.Id != null)
                                {
                                    var node = Umbraco.Content(result.Id);
                                    <li>
                                        <a href="@node.Url">@node.Name</a>
                                    </li>
                                }
                            }
                        </ul>
                    }
                    else
                    {
                        <p>No results found for query @searchTerm</p>
                    }
                }

(Where @searchTerm is coming from the form submit/query string)

If I search for 'blog', then these blog posts come through (correct)

  • Bloggish
  • Testing my blog post

Now, onto my blog search which is as below:

if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
        {
            var searcher = index.GetSearcher();
            var searchTerms = query.Split(' ').ToList().Select(s => s.Fuzzy()).ToArray();

            var results = searcher.CreateQuery("content").NodeTypeAlias("blogPost")
                .And().ParentId(model.Content.Id)
                .And().GroupedOr(new string[] { "nodeName", "title" }, searchTerms).Execute();
        }

(This code is in a controller, query = the search term in the query string)

If I search for 'blog' here, only the following appear:

  • Testing my blog post

The post 'Bloggish' is missing from the results. How can I adjust the code above so that it would be more flexible and pull through the right results?


Viewing all articles
Browse latest Browse all 72689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>