diff --git a/AssemblyVersion.cs b/AssemblyVersion.cs
index 755906c..9cefd4f 100644
--- a/AssemblyVersion.cs
+++ b/AssemblyVersion.cs
@@ -16,5 +16,5 @@ using System.Reflection;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("3.0.0.334")]
-[assembly: AssemblyFileVersion("3.0.0.334")]
+[assembly: AssemblyVersion("3.0.0.335")]
+[assembly: AssemblyFileVersion("3.0.0.335")]
diff --git a/Core/Formatter.cs b/Core/Formatter.cs
index f1d5d11..fb6d92b 100644
--- a/Core/Formatter.cs
+++ b/Core/Formatter.cs
@@ -316,7 +316,7 @@ namespace ScrewTurn.Wiki {
string nsstring = ns != null ? NameTools.GetFullName(ns.Name, "Search") + ".aspx" : "Search.aspx";
string doSearchFunction = "";
sb.Insert(match.Index, doSearchFunction +
- @" »");
+ @" »");
break;
case "CLOUD":
string cloud = BuildCloud(DetectNamespaceInfo(current));
diff --git a/SearchEngine-Tests/WordInfoCollectionTests.cs b/SearchEngine-Tests/WordInfoCollectionTests.cs
index a3e829c..3838669 100644
--- a/SearchEngine-Tests/WordInfoCollectionTests.cs
+++ b/SearchEngine-Tests/WordInfoCollectionTests.cs
@@ -95,6 +95,25 @@ namespace ScrewTurn.Wiki.SearchEngine.Tests {
Assert.IsFalse(collection.Contains(""), "Contains should return false");
}
+ [Test]
+ public void ContainsOccurrence() {
+ WordInfoCollection collection = new WordInfoCollection();
+
+ WordInfo mi1 = new WordInfo("continuous", 7, 0, WordLocation.Content);
+
+ collection.Add(mi1);
+
+ Assert.IsTrue(collection.ContainsOccurrence("continuous", 7), "Collection should contain occurrence");
+ Assert.IsFalse(collection.ContainsOccurrence("continuous2", 7), "Collection should not contain occurrence");
+ Assert.IsFalse(collection.ContainsOccurrence("continuous", 6), "Collection should not contain occurrence");
+ Assert.IsFalse(collection.ContainsOccurrence("continuous", 8), "Collection should not contain occurrence");
+ Assert.IsFalse(collection.ContainsOccurrence("continuous2", 6), "Collection should not contain occurrence");
+
+ Assert.IsFalse(collection.ContainsOccurrence("continuous2", -1), "Contains should return false");
+ Assert.IsFalse(collection.ContainsOccurrence("", 7), "Contains should return false");
+ Assert.IsFalse(collection.ContainsOccurrence(null, 7), "Contains should return false");
+ }
+
[Test]
public void CopyTo() {
WordInfoCollection collection = new WordInfoCollection();
diff --git a/SearchEngine/Tools.cs b/SearchEngine/Tools.cs
index 7df1190..a893afa 100644
--- a/SearchEngine/Tools.cs
+++ b/SearchEngine/Tools.cs
@@ -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;
diff --git a/SearchEngine/WordInfoCollection.cs b/SearchEngine/WordInfoCollection.cs
index 3e421d6..8ac210d 100644
--- a/SearchEngine/WordInfoCollection.cs
+++ b/SearchEngine/WordInfoCollection.cs
@@ -78,6 +78,23 @@ namespace ScrewTurn.Wiki.SearchEngine {
return false;
}
+ ///
+ /// Determines whether a word occurrence is in the collection.
+ ///
+ /// The word.
+ /// The index of the first character.
+ /// True if the collection contains the occurrence, false otherwise.
+ 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;
+ }
+
///
/// Copies the collection items to an array.
///
diff --git a/WebApplication/Search.aspx.cs b/WebApplication/Search.aspx.cs
index 4192961..be25492 100644
--- a/WebApplication/Search.aspx.cs
+++ b/WebApplication/Search.aspx.cs
@@ -489,7 +489,8 @@ namespace ScrewTurn.Wiki {
len = sb.Length - start;
endsAtEnd = true;
}
- else if(len > maxLen) len = maxLen;
+ if(len <= 0) len = sb.Length; // HACK: This should never occur, but if it does it crashes the wiki, so set it to max len
+ if(len > maxLen) len = maxLen;
result = sb.ToString();