Fixed issue in search engine (multiple identical matches returned when search query contained the same work multiple times).
This commit is contained in:
parent
4bb5211191
commit
e225f06bd1
6 changed files with 45 additions and 5 deletions
|
@ -16,5 +16,5 @@ using System.Reflection;
|
||||||
//
|
//
|
||||||
// You can specify all the values or you can default the Revision and Build Numbers
|
// You can specify all the values or you can default the Revision and Build Numbers
|
||||||
// by using the '*' as shown below:
|
// by using the '*' as shown below:
|
||||||
[assembly: AssemblyVersion("3.0.0.334")]
|
[assembly: AssemblyVersion("3.0.0.335")]
|
||||||
[assembly: AssemblyFileVersion("3.0.0.334")]
|
[assembly: AssemblyFileVersion("3.0.0.335")]
|
||||||
|
|
|
@ -316,7 +316,7 @@ namespace ScrewTurn.Wiki {
|
||||||
string nsstring = ns != null ? NameTools.GetFullName(ns.Name, "Search") + ".aspx" : "Search.aspx";
|
string nsstring = ns != null ? NameTools.GetFullName(ns.Name, "Search") + ".aspx" : "Search.aspx";
|
||||||
string doSearchFunction = "<nowiki><nobr><script type=\"text/javascript\"><!--\r\n" + @"function _DoSearch_" + textBoxId + "() { document.location = '" + nsstring + @"?AllNamespaces=1&FilesAndAttachments=1&Query=' + encodeURI(document.getElementById('" + textBoxId + "').value); }" + "\r\n// -->\r\n</script>";
|
string doSearchFunction = "<nowiki><nobr><script type=\"text/javascript\"><!--\r\n" + @"function _DoSearch_" + textBoxId + "() { document.location = '" + nsstring + @"?AllNamespaces=1&FilesAndAttachments=1&Query=' + encodeURI(document.getElementById('" + textBoxId + "').value); }" + "\r\n// -->\r\n</script>";
|
||||||
sb.Insert(match.Index, doSearchFunction +
|
sb.Insert(match.Index, doSearchFunction +
|
||||||
@"<input class=""txtsearchbox"" type=""text"" id=""" + textBoxId + @""" onkeydown=""javascript:var keycode; if(window.event) keycode = event.keyCode; else keycode = event.which; if(keycode == 10 || keycode == 13) { _DoSearch_" + textBoxId + @"(); return false; }"" /> <big><a href=""#"" onclick=""javascript:_DoSearch(); return false;"">»</a></big></nowiki></nobr>");
|
@"<input class=""txtsearchbox"" type=""text"" id=""" + textBoxId + @""" onkeydown=""javascript:var keycode; if(window.event) keycode = event.keyCode; else keycode = event.which; if(keycode == 10 || keycode == 13) { _DoSearch_" + textBoxId + @"(); return false; }"" /> <big><a href=""#"" onclick=""javascript:_DoSearch_" + textBoxId + @"(); return false;"">»</a></big></nowiki></nobr>");
|
||||||
break;
|
break;
|
||||||
case "CLOUD":
|
case "CLOUD":
|
||||||
string cloud = BuildCloud(DetectNamespaceInfo(current));
|
string cloud = BuildCloud(DetectNamespaceInfo(current));
|
||||||
|
|
|
@ -95,6 +95,25 @@ namespace ScrewTurn.Wiki.SearchEngine.Tests {
|
||||||
Assert.IsFalse(collection.Contains(""), "Contains should return false");
|
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]
|
[Test]
|
||||||
public void CopyTo() {
|
public void CopyTo() {
|
||||||
WordInfoCollection collection = new WordInfoCollection();
|
WordInfoCollection collection = new WordInfoCollection();
|
||||||
|
|
|
@ -61,7 +61,10 @@ namespace ScrewTurn.Wiki.SearchEngine {
|
||||||
results.Add(res);
|
results.Add(res);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
res.Relevance.SetValue(res.Relevance.Value + info.Location.RelativeRelevance);
|
||||||
}
|
}
|
||||||
totalRelevance += info.Location.RelativeRelevance;
|
totalRelevance += info.Location.RelativeRelevance;
|
||||||
|
|
|
@ -78,6 +78,23 @@ namespace ScrewTurn.Wiki.SearchEngine {
|
||||||
return false;
|
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>
|
/// <summary>
|
||||||
/// Copies the collection items to an array.
|
/// Copies the collection items to an array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -489,7 +489,8 @@ namespace ScrewTurn.Wiki {
|
||||||
len = sb.Length - start;
|
len = sb.Length - start;
|
||||||
endsAtEnd = true;
|
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();
|
result = sb.ToString();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue