Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kurtakov2015-02-25 12:24:51 +0000
committerAlexander Kurtakov2015-02-26 15:42:10 +0000
commitdc5c60901bf7086c08f866e85fe4641796ea384b (patch)
tree78b851d11ed10dba5c8d073de47bc6e4be1b7e64
parenta6190d03254c4ae1df848d21302535d7448ac770 (diff)
downloadeclipse.platform.ua-dc5c60901bf7086c08f866e85fe4641796ea384b.tar.gz
eclipse.platform.ua-dc5c60901bf7086c08f866e85fe4641796ea384b.tar.xz
eclipse.platform.ua-dc5c60901bf7086c08f866e85fe4641796ea384b.zip
Bug 460787 - Do not use deprecated Lucene 3.5 methods/classes
Moves from deprecated methods/classes to newer ones by simply redoing what the deprecated methods were doing in Lucene 3.5 itself using the newer APIs. This is preliminalry work for updating to Lucene 4.x/5.x where these deprecated ones are actually removed. Change-Id: I96937e00a251630a6927130efb88cc1652080cb9 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/Analyzer_en.java6
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/DefaultAnalyzer.java10
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/LowerCaseAndDigitsTokenizer.java6
-rw-r--r--org.eclipse.help.base/src/org/eclipse/help/internal/search/SearchIndex.java30
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/PrebuiltIndexCompatibility.java6
5 files changed, 38 insertions, 20 deletions
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/Analyzer_en.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/Analyzer_en.java
index 13157cf9f..a066aa4e3 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/Analyzer_en.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/Analyzer_en.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Alexander Kurtakov - Bug 460787
*******************************************************************************/
package org.eclipse.help.internal.search;
import java.io.*;
@@ -14,6 +15,7 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.analysis.*;
+import org.apache.lucene.util.Version;
/**
* Lucene Analyzer for English. LowerCaseTokenizer->StopFilter->PorterStemFilter
*/
@@ -29,7 +31,7 @@ public final class Analyzer_en extends Analyzer {
* Reader.
*/
public final TokenStream tokenStream(String fieldName, Reader reader) {
- return new PorterStemFilter(new StopFilter(false, new LowerCaseAndDigitsTokenizer(reader), getStopWords(), false));
+ return new PorterStemFilter(new StopFilter(Version.LUCENE_30, new LowerCaseAndDigitsTokenizer(reader), getStopWords(), false));
}
private Set<String> stopWords;
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/DefaultAnalyzer.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/DefaultAnalyzer.java
index b176e9de3..4109474ab 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/DefaultAnalyzer.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/DefaultAnalyzer.java
@@ -1,10 +1,12 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others. All rights reserved. This program and the
+ * Copyright (c) 2000, 2015 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
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Alexander Kurtakov - Bug 460787
*******************************************************************************/
package org.eclipse.help.internal.search;
@@ -17,7 +19,7 @@ import com.ibm.icu.text.BreakIterator;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.TokenStream;
-
+import org.apache.lucene.util.Version;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.core.runtime.Platform;
@@ -86,7 +88,7 @@ public final class DefaultAnalyzer extends Analyzer {
* Reader.
*/
public final TokenStream tokenStream(String fieldName, Reader reader) {
- return new LowerCaseFilter(new WordTokenStream(fieldName, reader, locale));
+ return new LowerCaseFilter(Version.LUCENE_30, new WordTokenStream(fieldName, reader, locale));
}
/**
diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/search/LowerCaseAndDigitsTokenizer.java b/org.eclipse.help.base/src/org/eclipse/help/internal/search/LowerCaseAndDigitsTokenizer.java
index 0dd3943e6..a475688d1 100644
--- a/org.eclipse.help.base/src/org/eclipse/help/internal/search/LowerCaseAndDigitsTokenizer.java
+++ b/org.eclipse.help.base/src/org/eclipse/help/internal/search/LowerCaseAndDigitsTokenizer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -7,12 +7,14 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Alexander Kurtakov - Bug 460787
*******************************************************************************/
package org.eclipse.help.internal.search;
import java.io.*;
import org.apache.lucene.analysis.*;
+import org.apache.lucene.util.Version;
/**
* Tokenizer breaking words around letters or digits.
@@ -20,7 +22,7 @@ import org.apache.lucene.analysis.*;
public class LowerCaseAndDigitsTokenizer extends CharTokenizer {
public LowerCaseAndDigitsTokenizer(Reader input) {
- super(input);
+ super(Version.LUCENE_30, input);
}
protected char normalize(char c) {
return Character.toLowerCase(c);
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 a66e73e48..33c9476b7 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
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Holger Voormann - fix for bug 426785 (http://eclip.se/426785)
+ * Alexander Kurtakov - Bug 460787
*******************************************************************************/
package org.eclipse.help.internal.search;
@@ -32,13 +33,17 @@ import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
+import org.apache.lucene.analysis.LimitTokenCountAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.index.IndexWriter.MaxFieldLength;
+import org.apache.lucene.index.IndexWriterConfig.OpenMode;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.LogByteSizeMergePolicy;
+import org.apache.lucene.index.LogMergePolicy;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
@@ -277,9 +282,13 @@ public class SearchIndex implements IHelpSearchIndex {
indexedDocs = new HelpProperties(INDEXED_DOCS_FILE, indexDir);
indexedDocs.restore();
setInconsistent(true);
- MaxFieldLength max = new MaxFieldLength(1000000);
- iw = new IndexWriter(luceneDirectory, analyzerDescriptor.getAnalyzer(), create, max);
- iw.setMergeFactor(20);
+ LimitTokenCountAnalyzer analyzer = new LimitTokenCountAnalyzer(analyzerDescriptor.getAnalyzer(), 1000000);
+ IndexWriterConfig writerConfig = new IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_31, analyzer);
+ writerConfig.setOpenMode(create ? OpenMode.CREATE : OpenMode.APPEND);
+ LogMergePolicy mergePolicy = new LogByteSizeMergePolicy();
+ mergePolicy.setMergeFactor(20);
+ writerConfig.setMergePolicy(mergePolicy);
+ iw = new IndexWriter(luceneDirectory, writerConfig);
return true;
} catch (IOException e) {
HelpBasePlugin.logError("Exception occurred in search indexing at beginAddBatch.", e); //$NON-NLS-1$
@@ -351,7 +360,7 @@ public class SearchIndex implements IHelpSearchIndex {
if (iw == null)
return false;
if (optimize)
- iw.optimize();
+ iw.forceMerge(1, true);
iw.close();
iw = null;
// save the update info:
@@ -506,8 +515,8 @@ public class SearchIndex implements IHelpSearchIndex {
}
Directory[] luceneDirs = dirList.toArray(new Directory[dirList.size()]);
try {
- iw.addIndexesNoOptimize(luceneDirs);
- iw.optimize();
+ iw.addIndexes(luceneDirs);
+ iw.forceMerge(1, true);
} catch (IOException ioe) {
HelpBasePlugin.logError("Merging search indexes failed.", ioe); //$NON-NLS-1$
return new HashMap<String, String[]>();
@@ -793,7 +802,7 @@ public class SearchIndex implements IHelpSearchIndex {
public void openSearcher() throws IOException {
synchronized (searcherCreateLock) {
if (searcher == null) {
- searcher = new IndexSearcher(luceneDirectory, false);
+ searcher = new IndexSearcher(IndexReader.open(luceneDirectory, false));
}
}
}
@@ -892,9 +901,10 @@ public class SearchIndex implements IHelpSearchIndex {
*/
private void cleanOldIndex() {
IndexWriter cleaner = null;
- MaxFieldLength max = new MaxFieldLength(10000);
+ LimitTokenCountAnalyzer analyzer = new LimitTokenCountAnalyzer(analyzerDescriptor.getAnalyzer(), 10000);
try {
- cleaner = new IndexWriter(luceneDirectory, analyzerDescriptor.getAnalyzer(), true, max);
+ cleaner = new IndexWriter(luceneDirectory, new IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_31, analyzer).setOpenMode(
+ OpenMode.CREATE));
} catch (IOException ioe) {
} finally {
try {
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
index 3f666f27e..640d4c9ad 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 IBM Corporation and others.
+ * Copyright (c) 2011, 2015 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Alexander Kurtakov - Bug 460787
*******************************************************************************/
package org.eclipse.ua.tests.help.search;
@@ -23,6 +24,7 @@ import junit.framework.TestSuite;
import org.osgi.framework.Bundle;
import org.apache.lucene.index.CorruptIndexException;
+import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TopDocs;
@@ -155,7 +157,7 @@ public class PrebuiltIndexCompatibility extends TestCase {
IndexSearcher searcher = null;
try {
luceneDirectory = new NIOFSDirectory(new File(filePath));
- searcher = new IndexSearcher(luceneDirectory, true);
+ searcher = new IndexSearcher(IndexReader.open(luceneDirectory, true));
TopDocs hits = searcher.search(luceneQuery, 500);
assertEquals(hits.totalHits, 1);
} finally {

Back to the top