Skip to content

Commit

Permalink
query fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
skttl committed Apr 18, 2024
1 parent 3380a4a commit 422fd8a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Our.Umbraco.FullTextSearch/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ private ISearchResults GetResults()

if (_search.SearchTerm.IsNullOrWhiteSpace() == false)
{
query.Append("(");
switch (_search.SearchType)
{
case SearchType.MultiRelevance:
Expand Down Expand Up @@ -124,22 +125,23 @@ private ISearchResults GetResults()
query.Append(QueryAllPropertiesAnd(_search.SearchTermSplit, 1.0));
break;
}
query.Append(")");
queryParts.Add(query.ToString());
}

if (_search.RootNodeIds.Any())
{
var rootNodeGroup = string.Join(" OR ", _search.RootNodeIds.Select(x =>
$"{_options.FullTextPathField}:{x}"));
queryParts.Add(rootNodeGroup);
queryParts.Add($"({rootNodeGroup})");
}

var allowedContentTypes = _search.AllowedContentTypes.Where(t => !string.IsNullOrWhiteSpace(t)).ToList();
if (allowedContentTypes.Any())
{
var contentTypeGroup = string.Join(" OR ", allowedContentTypes.Select(x =>
$"__NodeTypeAlias:{x}"));
queryParts.Add(contentTypeGroup);
queryParts.Add($"({contentTypeGroup})");
}


Expand Down Expand Up @@ -186,7 +188,7 @@ private ISearchResults GetResults()
}

query.Clear();
query.Append(string.Join(" AND ", queryParts.Select(x => $"({x})")));
query.Append(string.Join(" AND ", queryParts));

if (searcher != null)
{
Expand Down

0 comments on commit 422fd8a

Please sign in to comment.