Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2011-02-01 18:36:07 +0000
committerChris Goldthorpe2011-02-01 18:36:07 +0000
commitf29338d7538c4bc6614987fd901a875462ecadba (patch)
tree5c2387628abd2e60672094e1c652d35e69a21e8a
parentea112677edd551000c08279ea773e38af29c08e4 (diff)
downloadeclipse.platform.ua-f29338d7538c4bc6614987fd901a875462ecadba.tar.gz
eclipse.platform.ua-f29338d7538c4bc6614987fd901a875462ecadba.tar.xz
eclipse.platform.ua-f29338d7538c4bc6614987fd901a875462ecadba.zip
Bug 335997 - [Help] Allow indexes created with Lucene 1.9.1 to be read
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java4
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java35
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index191/_2.cfsbin0 -> 1043 bytes
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index191/deletablebin0 -> 4 bytes
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index191/indexed_contributions3
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index191/indexed_dependencies4
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index191/indexed_docs4
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index191/segmentsbin0 -> 27 bytes
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfsbin0 -> 792 bytes
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfxbin0 -> 256 bytes
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/indexed_contributions3
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/indexed_dependencies4
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/indexed_docs4
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/segments.genbin0 -> 20 bytes
-rw-r--r--org.eclipse.ua.tests/data/help/searchindex/index291/segments_2bin0 -> 222 bytes
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/AllSearchTests.java3
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java151
17 files changed, 199 insertions, 16 deletions
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java
index 9273e60e3..884fd369d 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/PluginIndex.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2011 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
@@ -129,7 +129,7 @@ public class PluginIndex {
}
}
- private boolean isCompatible(Bundle bundle, IPath prefixedPath) {
+ public boolean isCompatible(Bundle bundle, IPath prefixedPath) {
URL url = FileLocator.find(bundle, prefixedPath
.append(SearchIndex.DEPENDENCIES_VERSION_FILENAME), null);
if (url == null) {
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java
index ebd7cd8da..50930c748 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java
@@ -705,24 +705,33 @@ public class SearchIndex implements ISearchIndex, IHelpSearchIndex {
return isLuceneCompatible(usedLuceneVersion);
}
- public boolean isLuceneCompatible(String luceneVersion) {
- if (luceneVersion==null) return false;
- String currentLuceneVersion = ""; //$NON-NLS-1$
+ /**
+ * Determines whether an index can be read by the Lucene bundle
+ * @param indexVersionString The version of an Index directory
+ * @return
+ */
+ public boolean isLuceneCompatible(String indexVersionString) {
+ if (indexVersionString==null) return false;
+ String luceneVersionString = ""; //$NON-NLS-1$
Bundle luceneBundle = Platform.getBundle(LUCENE_BUNDLE_ID);
if (luceneBundle != null) {
- currentLuceneVersion += (String) luceneBundle.getHeaders()
+ luceneVersionString += (String) luceneBundle.getHeaders()
.get(Constants.BUNDLE_VERSION);
}
- //Direct comparison
- if (currentLuceneVersion.equals(luceneVersion))
+ Version luceneVersion = new Version(luceneVersionString);
+ Version indexVersion = new Version(indexVersionString);
+ Version v191 = new Version(1, 9, 1);
+ if (indexVersion.compareTo(v191) < 0) {
+ // index is older than Lucene 1.9.1
+ return false;
+ }
+ if ( luceneVersion.compareTo(indexVersion) >= 0 ) {
+ // Lucene bundle is newer than the index
return true;
- Version version = new Version(currentLuceneVersion);
- Version currentVersion = new Version(luceneVersion);
- // must not compare with the qualifier because they
- // change from build to build
- return version.getMajor() == currentVersion.getMajor()
- && version.getMinor() == currentVersion.getMinor()
- && version.getMicro() == currentVersion.getMicro();
+ }
+ return luceneVersion.getMajor() == indexVersion.getMajor()
+ && luceneVersion.getMinor() == indexVersion.getMinor()
+ && luceneVersion.getMicro() == indexVersion.getMicro();
}
private boolean isAnalyzerCompatible() {
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index191/_2.cfs b/org.eclipse.ua.tests/data/help/searchindex/index191/_2.cfs
new file mode 100644
index 000000000..38270b7ca
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index191/_2.cfs
Binary files differ
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index191/deletable b/org.eclipse.ua.tests/data/help/searchindex/index191/deletable
new file mode 100644
index 000000000..593f4708d
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index191/deletable
Binary files differ
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_contributions b/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_contributions
new file mode 100644
index 000000000..1adf36eea
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_contributions
@@ -0,0 +1,3 @@
+#This is a generated file; do not edit.
+#Mon Jan 31 14:18:32 PST 2011
+temp.preindex=temp.preindex\n1.0.0.qualifier
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_dependencies b/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_dependencies
new file mode 100644
index 000000000..9214feb01
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_dependencies
@@ -0,0 +1,4 @@
+#This is a generated file; do not edit.
+#Mon Jan 31 14:18:32 PST 2011
+lucene=1.9.1.v20100518-1140
+analyzer=org.eclipse.help.base\#3.5.0.v201006080911?locale\=en
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_docs b/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_docs
new file mode 100644
index 000000000..3c8e60b06
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index191/indexed_docs
@@ -0,0 +1,4 @@
+#This is a generated file; do not edit.
+#Mon Jan 31 14:18:32 PST 2011
+/temp.preindex/html/toc.html=0
+/temp.preindex/html/maintopic.html=0
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index191/segments b/org.eclipse.ua.tests/data/help/searchindex/index191/segments
new file mode 100644
index 000000000..3e2faebfa
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index191/segments
Binary files differ
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfs b/org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfs
new file mode 100644
index 000000000..50268681f
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfs
Binary files differ
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfx b/org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfx
new file mode 100644
index 000000000..b543bbbfb
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/_0.cfx
Binary files differ
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_contributions b/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_contributions
new file mode 100644
index 000000000..c310cb75d
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_contributions
@@ -0,0 +1,3 @@
+#This is a generated file; do not edit.
+#Mon Jan 31 12:37:00 PST 2011
+org.eclipse.ua.tests.preindex=org.eclipse.ua.tests.preindex\n1.0.0.qualifier
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_dependencies b/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_dependencies
new file mode 100644
index 000000000..e373197aa
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_dependencies
@@ -0,0 +1,4 @@
+#This is a generated file; do not edit.
+#Mon Jan 31 12:37:00 PST 2011
+lucene=2.9.1.v201101211721
+analyzer=org.eclipse.help.base\#3.6.0.v201101272034?locale\=en
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_docs b/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_docs
new file mode 100644
index 000000000..30b5c08d2
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/indexed_docs
@@ -0,0 +1,4 @@
+#This is a generated file; do not edit.
+#Mon Jan 31 12:37:00 PST 2011
+/org.eclipse.ua.tests.preindex/html/maintopic.html=0
+/org.eclipse.ua.tests.preindex/html/toc.html=0
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/segments.gen b/org.eclipse.ua.tests/data/help/searchindex/index291/segments.gen
new file mode 100644
index 000000000..225a55b3c
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/segments.gen
Binary files differ
diff --git a/org.eclipse.ua.tests/data/help/searchindex/index291/segments_2 b/org.eclipse.ua.tests/data/help/searchindex/index291/segments_2
new file mode 100644
index 000000000..653504e66
--- /dev/null
+++ b/org.eclipse.ua.tests/data/help/searchindex/index291/segments_2
Binary files differ
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 f8cf33196..7e0fd10aa 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2010 IBM Corporation and others.
+ * Copyright (c) 2006, 2011 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
@@ -45,5 +45,6 @@ public class AllSearchTests extends TestSuite {
addTest(LuceneXMLParticipantTest.suite());
addTestSuite(WorkingSetManagerTest.class);
addTestSuite(InfocenterWorkingSetManagerTest.class);
+ addTestSuite(PrebuiltIndexCompatibility.class);
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java
new file mode 100644
index 000000000..8206ef994
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.NIOFSDirectory;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.help.internal.base.BaseHelpSystem;
+import org.eclipse.help.internal.search.AnalyzerDescriptor;
+import org.eclipse.help.internal.search.PluginIndex;
+import org.eclipse.help.internal.search.QueryBuilder;
+import org.eclipse.help.internal.search.SearchIndexWithIndexingProgress;
+import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
+import org.osgi.framework.Bundle;
+
+/**
+ * Verify that older versions of the index can be read by this
+ * version of Eclipse.
+ *
+ * How to maintain this test - if when upgrading to a new version
+ * of Lucene one of the IndexReadable tests fails you need to
+ * make the following changes:
+ * 1. Change the corresponding Compatible() test to expect a result of false
+ * 2. Comment out the failing test
+ * 3. Change the help system to recognize that version of Lucene as being incompatible
+ */
+
+public class PrebuiltIndexCompatibility extends TestCase {
+
+ /*
+ * Returns an instance of this Test.
+ */
+ public static Test suite() {
+ return new TestSuite(PrebuiltIndexCompatibility.class);
+ }
+
+ /**
+ * Test index built with Lucene 1.9.1
+ */
+ public void test1_9_1_IndexReadable() throws Exception {
+ checkReadable("data/help/searchindex/index191");
+ }
+
+ /**
+ * Test index built with Lucene 2.9.1
+ */
+ public void test2_9_1_IndexReadable() throws Exception {
+ checkReadable("data/help/searchindex/index291");
+ }
+
+ /**
+ ** Test compatibility of Lucene 1.9.1 index with current Lucene
+ */
+ public void test1_9_1Compatible()
+ {
+ checkCompatible("data/help/searchindex/index191", true);
+ }
+
+ /**
+ ** Test compatibility of Lucene 2.9.1 index with current Lucene
+ */
+ public void test2_9_1Compatible()
+ {
+ checkCompatible("data/help/searchindex/index291", true);
+ }
+
+ public void test1_9_1LuceneCompatible()
+ {
+ checkLuceneCompatible("1.9.1", true);
+ }
+
+ public void test1_4_103NotLuceneCompatible()
+ {
+ checkLuceneCompatible("1.4.103", false);
+ }
+
+ public void test2_9_1LuceneCompatible()
+ {
+ checkLuceneCompatible("2.9.1", true);
+ }
+
+ /*
+ * Verifies that a prebuilt index can be searched
+ */
+ private void checkReadable(String indexPath) throws IOException,
+ CorruptIndexException {
+ Path path = new Path(indexPath);
+ Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
+ URL url = FileLocator.find(bundle, path, null);
+ URL resolved = FileLocator.resolve(url);
+ if ("file".equals(resolved.getProtocol())) { //$NON-NLS-1$
+ String filePath = resolved.getFile();
+ Directory luceneDirectory = new NIOFSDirectory(new File(filePath));
+ IndexSearcher searcher = new IndexSearcher(luceneDirectory, true);
+ QueryBuilder queryBuilder = new QueryBuilder("eclipse", new AnalyzerDescriptor("en-us"));
+ Query luceneQuery = queryBuilder.getLuceneQuery(new ArrayList() , false);
+ TopDocs hits = searcher.search(luceneQuery, 500);
+ assertEquals(hits.totalHits, 1);
+ } else {
+ fail("Cannot resolve to file protocol");
+ }
+ }
+
+ /*
+ * Tests the isCompatible method in PluginIndex
+ */
+ private void checkCompatible(String versionDirectory, boolean expected) {
+ SearchIndexWithIndexingProgress index = BaseHelpSystem.getLocalSearchManager().getIndex("en_us".toString());
+ BaseHelpSystem.getLocalSearchManager().ensureIndexUpdated(
+ new NullProgressMonitor(),
+ index);
+ Path path = new Path(versionDirectory);
+ PluginIndex pluginIndex = new PluginIndex("org.eclipse.ua.tests", "data/help/searchindex/" + versionDirectory, index);
+ assertEquals(expected, pluginIndex.isCompatible(UserAssistanceTestPlugin.getDefault().getBundle(), path));
+ }
+
+ /*
+ * Tests the isLuceneCompatible method in SearchIndex
+ */
+ private void checkLuceneCompatible(String version, boolean expected) {
+ SearchIndexWithIndexingProgress index = BaseHelpSystem.getLocalSearchManager().getIndex("en_us".toString());
+ BaseHelpSystem.getLocalSearchManager().ensureIndexUpdated(
+ new NullProgressMonitor(),
+ index);
+ assertEquals(expected, index.isLuceneCompatible(version));
+ }
+
+}

Back to the top