Tables:
Item
Id
Keyword
Id
Keyword
ItemKeyword
ItemId
KeywordId
SequenceNumber
for searching items via keyword:
Keyword keyword = Keyword.FirstOrDefault(a => a.Keyword
.Equals(input, StringComparison.InvariantCultureIgnoreCase));
IEnumerable<Item> items = keyword.ItemKeyword.OrderBy(a => a.SequenceNumber)
.SelectMany(a => a.Item);
for getting related keywords:
IEnumerable<Keyword> relatedKeywords = items.ItemKeyword
.SelectMany(a => a.Keyword)
.Except(keyword);
IEnumerable<Keyword> orderedRelatedKeywords = relatedKeywords
.OrderByDescending(a => relatedKeywords
.Where(b => b
.Keyword.Equals(a.Keyword, StringComparison.InvariantCultureIgnoreCase))
.Count())
.Distinct();
I don't have a development computer with me right now, but I hope you get my idea. My real problem here is arranging in descending order the relatedKeywords by the times it has been used. Are there any ways we could do this? Thanks.