Search query not pulling through the right results
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?
Search query not pulling through the right results
I'm trying to set up a site search and a blog search. Currently for the site search I have:
(Where @searchTerm is coming from the form submit/query string)
If I search for 'blog', then these blog posts come through (correct)
Now, onto my blog search which is as below:
(This code is in a controller, query = the search term in the query string)
If I search for 'blog' here, only the following appear:
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?
Sometimes when I have search issues I try to rebuild the Examine index.
Hi Amir,
I don't believe this to be an index issue. Because, if I remove:
leaving the rest of the query as is, it is able to pull through both "testing my blog post" and "bloggish".
Grabbed this from one of our blog searches, which I know works. Obvi some extra fields for our setup.
Maybe give this a try and see if you get the desired results.
Which version of Umbraco is this for?
I'm on 8.6.3 and I'm unable to use:
Additionally, I have no option to use Compile() on the search query.
is working on a reply...