You have an issue while adding search term predicate to your query.
You just have your main query and you add OR Title Like SearchTerm OR ...
so it's enough that title contains search term and it none of the other conditions is needed to evaluate to true
:
if (!string.IsNullOrWhiteSpace(searchTerm))
{
andPredicate = andPredicate.And(x => x.Title.Like(searchTerm, 0.75f));
foreach (var t in searchTerm.Split(' '))
{
var tempTerm = t;
andPredicate = andPredicate.Or(p => p.Title.MatchWildcard(tempTerm + "*").Boost(5.5f));
andPredicate = andPredicate.Or(p => p.Title.MatchWildcard(tempTerm + "*"));
andPredicate = andPredicate.Or(p => p.Title.Equals(tempTerm));
}
}
Instead it should be:
if (!string.IsNullOrWhiteSpace(searchTerm))
{
var titlePredicate = PredicateBuilder.False<ProductSearchResultItem>();
titlePredicate = titlePredicate.Or(x => x.Title.Like(searchTerm, 0.75f));
foreach (var t in searchTerm.Split(' '))
{
var tempTerm = t;
titlePredicate = titlePredicate.Or(p => p.Title.MatchWildcard(tempTerm + "*").Boost(5.5f));
titlePredicate = titlePredicate.Or(p => p.Title.MatchWildcard(tempTerm + "*"));
titlePredicate = titlePredicate.Or(p => p.Title.Equals(tempTerm));
}
andPredicate = andPredicate.And(titlePredicate);
}