I need to generate an autocomplete sugestions list of Keywords based on a search, where each keyword has a set of KeywordSearch:
Keyword class:
public class Keyword
{
public int Id { get; set; }
public string Name { get; set; }
}
public class KeywordSearch
{
// Primary properties
public int Id { get; set; }
public string Name { get; set; }
public Keyword Keyword { get; set; }
}
So If have a keyword like "Company Name", I will have the KeywordSearch "Company" and "Name".
The function I have now, that is not working well is:
public IList<KeywordDto> GetAllBySearch(string keywords, int numberOfRecords)
{
var splitKeywords = keywords.Split(new Char[] { ' ' });
var keywordQuery = _keywordRepository.Query.Where(p => p.IsActive == true);
var keywordSearchQuery = _keywordSearchRepository.Query;
var keywordIds = keywordSearchQuery
.GroupBy(k => k.Keyword.Id)
.Where(g => splitKeywords.All(w => g.Any(k => w.Contains(k.Name))))
.Select(g => g.Key);
IList<KeywordDto> keywordList = (from kw in keywordQuery
join kwids in keywordIds on kw.Id equals kwids
select new KeywordDto { Id = kw.Id, Name = kw.Name })
.Take(numberOfRecords)
.Distinct()
.OrderBy(p => p.Name).ToList();
return keywordList;
}
I need to build a KeywordList based on the keywords string, so if keywords = "Compa" I return "Company Name" with the part "Comp" with bold style , or if keywords = "Compa Nam" I return "Company Name" with "Compa Nam" with bold style etc...
Now what is happening is that it's not able to find the part "Comp" in the KeywordSearch.
Any Suggestion?
Thanks