We're having a problem with searches for queries like 3/4"
. What we want is products to be returned that have this text in any of the searched fields. For example, three quarter inch plumbing parts woudl be expected. What we get though are things that have 3/4"
in our searched fields (that's what we want) but also anything that has a "3" or a "4" in the searched fields. This results in a significant amount of undesired/unrelated results.
I'm currently working on some new search code (Find) that exhibits this behavior:
var search = _searchClient.Search<BaseVariationContent>(Language.English);
var filters = filter == null ? null : Server.UrlDecode(filter).Split(',');
search = search.For(query)
.InField(x => x.WebDescription.ToString())
.InField(x => x.GetDisplayName())
.InField(x => x.Code)
.InField(x => x.ManufacturerPartNo)
.InField(x => x.CrossItems)
.InField(x => x.Type)
.UsingSynonyms()
.Take(take)
.BoostMatching(x => x.ProductCategoryField().SubCategoryName.MatchCaseInsensitive(query), 2)
.BoostMatching(x => x.Code.Match(query), 2)
.BoostMatching(x => x.CrossItems.Match(query), 1)
.BoostMatching(x => x.GetDisplayName().MatchCaseInsensitive(query), 2)
.ApplyBestBets()
.WildcardSearch(query,
(x => x.Code, 2),
(x => x.CrossItems, 1),
(x => x.GetDisplayName(), 1)
)
.TermsFacetFor(x => x.ProductCategoryField().SubCategoryName);
if (filters != null && filters.Any())
{
var facetFilter = new FilterBuilder<BaseVariationContent>(search.Client);
foreach (var nextFilter in filters)
{
if (!string.IsNullOrEmpty(nextFilter))
{
facetFilter = facetFilter.Or(x => x.ProductCategoryField().SubCategoryName.Match(nextFilter));
}
}
search = search.FilterHits(facetFilter);
}
var result = search.GetContentResult();