3
我有以下查詢偉大的工程:LINQ算OCCURENCES
string[] Words = {"search","query","example"};
... Snip ...
var Results = (
from a in q
from w in Words
where
(
a.Title.ToLower().Contains(w)
|| a.Body.ToLower().Contains(w)
)
select new
{
a,
Count = 0
}).OrderByDescending(x=> x.Count)
.Distinct()
.Take(Settings.ArticlesPerPage);
我需要它做什麼,是返回Count
這是一家之言總髮生。我將它重量有利於標題爲好,例如:
Count = (OccuranceInTitle * 5) + (OccurancesInBody)
我假設我需要使用Linq.Count,但我不知道如何在這種情況下應用它。
打我吧:-) –
哦,那真是太聰明瞭!這甚至自然更重要的更長的單詞,我喜歡它!只是爲了檢查,title.Replace(w,string.Empty)會用單詞組成一個單詞嗎? –
這很危險。它以「The Boring Bookkeepers」這個標題來衡量「Book」。 「同樣的」a「在」德克薩斯州犰狳Aardvarks「中佔有一席之地。 – jason