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:
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.
from p in _productRepository.Table
where p.Name.Contains(keywords) ||
(p.ShortDescription.Contains(keywords) || p.FullDescription.Contains(keywords))) ||
(searchManufacturerPartNumber && p.ManufacturerPartNumber == keywords) ||
(searchSku && p.Sku == keywords)
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: