Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2010-08-26 23:45:13 +0000
committerChris Goldthorpe2010-08-26 23:45:13 +0000
commitb1b38298f7e05a518eb25f7e0acc2b2cf3a648a6 (patch)
tree6a15512bdd89d3500dcaab44684159919d8f08cd
parent5b7a1049c22195537639e69e77a35ee047850a1e (diff)
downloadeclipse.platform.ua-b1b38298f7e05a518eb25f7e0acc2b2cf3a648a6.tar.gz
eclipse.platform.ua-b1b38298f7e05a518eb25f7e0acc2b2cf3a648a6.tar.xz
eclipse.platform.ua-b1b38298f7e05a518eb25f7e0acc2b2cf3a648a6.zip
Add test for search rankingv20100830
-rw-r--r--org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1a.htm24
-rw-r--r--org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1b.htm26
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java1
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchRanking.java70
4 files changed, 121 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1a.htm b/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1a.htm
new file mode 100644
index 000000000..4cacda324
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1a.htm
@@ -0,0 +1,24 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<!--
+ Copyright (c) 2010 IBM Corporation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ IBM Corporation - initial API and implementation
+ -->
+<html>
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Searchable word odrgtb</title>
+</head>
+<body>
+
+This is a test document to make sure hits in the title get a higher rank
+than hits in the body of texts. Searchable word mjuhgt
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1b.htm b/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1b.htm
new file mode 100644
index 000000000..a1e0bce11
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1b.htm
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<!--
+ Copyright (c) 2010 IBM Corporation and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ IBM Corporation - initial API and implementation
+ -->
+<html>
+<head>
+<meta http-equiv="Content-Language" content="en-us">
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Searchable word mjuhgt</title>
+</head>
+<body>
+
+This is a test document to make sure hits in the title get a higher rank
+than hits in the body of texts.
+
+Searchable word odrgtb
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java
index a22bcbb43..f8cf33196 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java
@@ -40,6 +40,7 @@ public class AllSearchTests extends TestSuite {
addTest(MetaKeywords.suite());
addTest(SearchParticipantTest.suite());
addTest(SearchParticipantXMLTest.suite());
+ addTest(SearchRanking.suite());
addTest(LuceneParticipantTest.suite());
addTest(LuceneXMLParticipantTest.suite());
addTestSuite(WorkingSetManagerTest.class);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchRanking.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchRanking.java
new file mode 100644
index 000000000..e9d8ad125
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/SearchRanking.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.ua.tests.help.search;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.help.internal.base.BaseHelpSystem;
+import org.eclipse.help.internal.search.ISearchQuery;
+import org.eclipse.help.internal.search.SearchHit;
+import org.eclipse.help.internal.search.SearchQuery;
+import org.eclipse.help.internal.search.SearchResults;
+
+public class SearchRanking extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(SearchRanking.class);
+ }
+
+ public SearchHit[] findHits(String searchWord) {
+ ISearchQuery query = new SearchQuery(searchWord, false, new ArrayList(), Platform.getNL());
+ SearchResults collector = new SearchResults(null, 10, Platform.getNL());
+ BaseHelpSystem.getSearchManager().search(query, collector, new NullProgressMonitor());
+ return collector.getSearchHits();
+ }
+
+ /**
+ * Verify that a match in a title has more weight than a match in the body
+ */
+ public void testTitleBoost1() {
+ SearchHit[] hits = SearchTestUtils.getSearchHits("mjuhgt", "en");
+ Arrays.sort(hits);
+ assertEquals(2, hits.length);
+ assertEquals("/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1b.htm", getPath(hits[0]));
+ assertEquals("/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1a.htm", getPath(hits[1]));
+ }
+
+ public void testTitleBoost2() {
+ SearchHit[] hits = SearchTestUtils.getSearchHits("odrgtb", "en");
+ Arrays.sort(hits);
+ assertEquals(2, hits.length);
+ assertEquals("/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1a.htm", getPath(hits[0]));
+ assertEquals("/org.eclipse.ua.tests/data/help/search/extraDir/ranking/ranktest1b.htm", getPath(hits[1]));
+ }
+
+ private String getPath(SearchHit hit) {
+ String href = hit.getHref();
+ int query = href.indexOf('?');
+ return query < 0 ? href : href.substring(0, query);
+ }
+
+}

Back to the top