Fixed issue in search engine (multiple identical matches returned when search query contained the same work multiple times).

This commit is contained in:
Dario Solera 2009-10-02 08:00:55 +00:00
parent 4bb5211191
commit e225f06bd1
6 changed files with 45 additions and 5 deletions

View file

@ -61,7 +61,10 @@ namespace ScrewTurn.Wiki.SearchEngine {
results.Add(res);
}
else {
res.Matches.Add(mi);
// Avoid adding duplicate matches (happens when query contains the same word multiple times)
if(!res.Matches.ContainsOccurrence(mi.Text, mi.FirstCharIndex)) {
res.Matches.Add(mi);
}
res.Relevance.SetValue(res.Relevance.Value + info.Location.RelativeRelevance);
}
totalRelevance += info.Location.RelativeRelevance;

View file

@ -78,6 +78,23 @@ namespace ScrewTurn.Wiki.SearchEngine {
return false;
}
/// <summary>
/// Determines whether a word occurrence is in the collection.
/// </summary>
/// <param name="word">The word.</param>
/// <param name="firstCharIndex">The index of the first character.</param>
/// <returns><c>True</c> if the collection contains the occurrence, <c>false</c> otherwise.</returns>
public bool ContainsOccurrence(string word, int firstCharIndex) {
if(string.IsNullOrEmpty(word)) return false;
if(firstCharIndex < 0) return false;
foreach(WordInfo w in items) {
if(w.Text == word && w.FirstCharIndex == firstCharIndex) return true;
}
return false;
}
/// <summary>
/// Copies the collection items to an array.
/// </summary>