If I have two product:
Product 01 Name: $50 Physical Gift Card
Product 02 Name: $100 Physical Gift Card
Then, Search by gift card give me both products in search result, but if I search by physical card then no product returns in search result. That means if I don't provide consecutive word of product name the search on product name doesn't work.
Here are some forum post point to this:
1. https://www.nopcommerce.com/en/boards/topic/92804/search-box-finds-consecutive-wording-for-multiple-words-only-can-this-be-changed#291257
2. https://www.nopcommerce.com/en/boards/topic/92462/v440-help-needed-trying-to-modify-searchproducts#289985
Proposed Solution:
I would suggest to include exclusive product name search.
An additional method,
private IQueryable<int> ExclusiveKeyWordSearch(string keywords)
{
var products = _productRepository.Table;
var searchstrings = keywords.Split(null).Select(x => x.ToLower()).ToArray();
foreach (string q in searchstrings)
{
products = products.Where(p => p.Name.ToLower().Contains(q));
}
return products.Select(p=> p.Id);
}
Then on ProductService, keep existing keywords search as it is and include this as an addition.
IQueryable<int> productsByKeywords;
productsByKeywords =
from p in _productRepository.Table
where p.Name.Contains(keywords) ||
(searchDescriptions &&
(p.ShortDescription.Contains(keywords) || p.FullDescription.Contains(keywords))) ||
(searchManufacturerPartNumber && p.ManufacturerPartNumber == keywords) ||
(searchSku && p.Sku == keywords)
select p.Id;
productsByKeywords = productsByKeywords.Union(ExclusiveKeyWordSearch(keywords));
On the ExclusiveKeyWordSearch method I think it's better to skip search on product Descriptions, as this might create performance issue.
Also, I would recommend to make it configurable. As it might impact the search performance, admin can decide whether they want to enable it or not!
The outcome of this modification is:
