diff --git a/org.eclipse.mylyn.tasks.index.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.index.core/META-INF/MANIFEST.MF index ee6bb21..7964cbc 100644 --- a/org.eclipse.mylyn.tasks.index.core/META-INF/MANIFEST.MF +++ b/org.eclipse.mylyn.tasks.index.core/META-INF/MANIFEST.MF @@ -7,7 +7,9 @@ Bundle-Vendor: %Bundle-Vendor Require-Bundle: org.eclipse.core.runtime, org.eclipse.mylyn.tasks.core;bundle-version="3.8.0", org.eclipse.mylyn.commons.core;bundle-version="3.8.0", - org.apache.lucene.core;bundle-version="[2.9.1,3.7.0)" + org.apache.lucene.core;bundle-version="[4.0.0,5.0.0)", + org.apache.lucene.queryparser;bundle-version="[4.0.0,5.0.0)", + org.apache.lucene.analysis;bundle-version="[4.0.0,5.0.0)" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.mylyn.internal.tasks.index.core;x-internal:=true diff --git a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskAnalyzer.java b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskAnalyzer.java index b1b88c1..581d390 100644 --- a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskAnalyzer.java +++ b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskAnalyzer.java @@ -11,23 +11,27 @@ *******************************************************************************/ package org.eclipse.mylyn.internal.tasks.index.core; -import org.apache.lucene.analysis.KeywordAnalyzer; -import org.apache.lucene.analysis.PerFieldAnalyzerWrapper; +import java.util.HashMap; +import java.util.Map; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.core.KeywordAnalyzer; +import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.util.Version; /** * An analyzer that is aware of task fields - * + * * @author David Green */ class TaskAnalyzer { public static PerFieldAnalyzerWrapper instance() { - PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(Version.LUCENE_CURRENT)); - wrapper.addAnalyzer(TaskListIndex.FIELD_IDENTIFIER.getIndexKey(), new KeywordAnalyzer()); - wrapper.addAnalyzer(TaskListIndex.FIELD_TASK_KEY.getIndexKey(), new KeywordAnalyzer()); - wrapper.addAnalyzer(TaskListIndex.FIELD_REPOSITORY_URL.getIndexKey(), new KeywordAnalyzer()); + Map analyzerPerField = new HashMap(); + analyzerPerField.put(TaskListIndex.FIELD_IDENTIFIER.getIndexKey(), new KeywordAnalyzer()); + analyzerPerField.put(TaskListIndex.FIELD_TASK_KEY.getIndexKey(), new KeywordAnalyzer()); + analyzerPerField.put(TaskListIndex.FIELD_REPOSITORY_URL.getIndexKey(), new KeywordAnalyzer()); + PerFieldAnalyzerWrapper wrapper = new PerFieldAnalyzerWrapper(new StandardAnalyzer(), analyzerPerField); return wrapper; } } diff --git a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java index 119ab2d..378b3a6 100644 --- a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java +++ b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java @@ -36,14 +36,18 @@ import java.util.logging.Logger; import org.apache.lucene.document.DateTools; import org.apache.lucene.document.DateTools.Resolution; import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Store; +import org.apache.lucene.document.StringField; +import org.apache.lucene.document.TextField; import org.apache.lucene.index.CorruptIndexException; +import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.Term; -import org.apache.lucene.queryParser.ParseException; -import org.apache.lucene.queryParser.QueryParser; +import org.apache.lucene.queryparser.classic.ParseException; +import org.apache.lucene.queryparser.classic.QueryParser; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; @@ -57,6 +61,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.store.NIOFSDirectory; +import org.apache.lucene.util.InfoStream; import org.apache.lucene.util.Version; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -111,7 +116,7 @@ import org.eclipse.mylyn.tasks.core.data.TaskData; * intensive long-running operation. With about 20,000 tasks in my task list and an SSD, reindexing takes about 90 * seconds. *

- * + * * @author David Green * @author Steffen Pingel */ @@ -316,7 +321,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * Create an index on the given task list. Must be matched by a corresponding call to {@link #close()}. - * + * * @param taskList * the task list that is to be indexed * @param dataManager @@ -334,7 +339,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * Create an index on the given task list. Must be matched by a corresponding call to {@link #close()}. - * + * * @param taskList * the task list that is to be indexed * @param dataManager @@ -358,7 +363,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * Create an index on the given task list. Must be matched by a corresponding call to {@link #close()}. - * + * * @param taskList * the task list that is to be indexed * @param dataManager @@ -385,7 +390,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * the delay before reindexing occurs after a task has changed or after {@link #reindex()} is called. - * + * * @param reindexDelay * The delay in miliseconds. Specify 0 to indicate no delay. */ @@ -459,7 +464,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * the default field used to match tasks when unspecified in the query - * + * * @param defaultField * the default field to use in queries, must be one of the {@link #getIndexedFields() indexed fields}. */ @@ -552,7 +557,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL * this method using the same pattern string do not require use of the backing index, making this method very * efficient for multiple calls with the same pattern string. Cached results for a given pattern string are * discarded if this method is called with a different pattern string. - * + * * @param task * the task to match * @param patternString @@ -591,12 +596,6 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL } catch (IOException e) { StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN, "Unexpected failure within task list index", e)); //$NON-NLS-1$ - } finally { - try { - indexSearcher.close(); - } catch (IOException e) { - // ignore - } } } else { @@ -625,7 +624,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * call to wait until index maintenance has completed - * + * * @throws InterruptedException */ public void waitUntilIdle() throws InterruptedException { @@ -639,7 +638,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * finds tasks that match the given pattern string - * + * * @param patternString * the pattern string, used to match tasks * @param collector @@ -674,12 +673,6 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL } catch (IOException e) { StatusHandler.log(new Status(IStatus.ERROR, TasksIndexCore.ID_PLUGIN, "Unexpected failure within task list index", e)); //$NON-NLS-1$ - } finally { - try { - indexSearcher.close(); - } catch (IOException e) { - // ignore - } } } } finally { @@ -696,7 +689,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL if (!hasBooleanSpecifiers && defaultField.equals(FIELD_SUMMARY) && !containsSpecialCharacters(patternString)) { return new PrefixQuery(new Term(defaultField.getIndexKey(), patternString)); } - QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, defaultField.getIndexKey(), TaskAnalyzer.instance()); + QueryParser qp = new QueryParser(defaultField.getIndexKey(), TaskAnalyzer.instance()); Query q; try { q = qp.parse(patternString); @@ -769,7 +762,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL try { synchronized (this) { if (indexReader == null) { - indexReader = IndexReader.open(directory, true); + indexReader = DirectoryReader.open(directory); lastResults = null; } return indexReader; @@ -816,7 +809,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * advanced usage: cause the given task to be reindexed using {@link MaintainIndexType#REINDEX reindex scheduling * rule}. - * + * * @param task * the task * @param taskData @@ -983,15 +976,14 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL if (value == null) { return; } - Field field = document.getField(indexField.getIndexKey()); + IndexableField field = document.getField(indexField.getIndexKey()); if (field == null) { - field = new Field(indexField.getIndexKey(), value, Store.YES, - org.apache.lucene.document.Field.Index.ANALYZED); + field = new TextField(indexField.getIndexKey(), value, Store.YES); document.add(field); } else { String existingValue = field.stringValue(); if (!indexField.equals(FIELD_PERSON) || !existingValue.contains(value)) { - field.setValue(existingValue + " " + value); //$NON-NLS-1$ + document.add(new StringField(field.name(), existingValue + " " + value, Store.YES)); //$NON-NLS-1$ } } } @@ -1004,19 +996,18 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL // move the date by the GMT offset if there is any String value = DateTools.dateToString(date, Resolution.HOUR); - Field field = document.getField(indexField.getIndexKey()); + IndexableField field = document.getField(indexField.getIndexKey()); if (field == null) { - field = new Field(indexField.getIndexKey(), value, Store.YES, - org.apache.lucene.document.Field.Index.ANALYZED); + field = new TextField(indexField.getIndexKey(), value, Store.YES); document.add(field); } else { - field.setValue(value); + document.add(new StringField(field.name(), value, Store.YES)); } } /** * Computes a query element for a field that must lie in a specified date range. - * + * * @param field * the field * @param lowerBoundInclusive @@ -1037,7 +1028,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL * the task data. In this way implementations can avoid loading task data if the decision to filter tasks can be * based on the ITask alone. Implementations that must read the task data in order to determine eligibility for * indexing should return true for tasks where the provided task data is null. - * + * * @param task * the task * @param taskData @@ -1051,7 +1042,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL /** * Escapes special characters in the given literal value so that they are not interpreted as special characters in a * query. - * + * * @param value * the value to escape * @return a representation of the value with characters escaped @@ -1069,7 +1060,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL try { if (!rebuildIndex) { try { - IndexReader reader = IndexReader.open(directory, false); + IndexReader reader = DirectoryReader.open(directory); reader.close(); } catch (CorruptIndexException e) { rebuildIndex = true; @@ -1119,7 +1110,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL } private void indexQueuedTasks(SubMonitor monitor) throws CorruptIndexException, LockObtainFailedException, - IOException, CoreException { + IOException, CoreException { synchronized (reindexQueue) { if (reindexQueue.isEmpty()) { @@ -1201,7 +1192,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL } private IStatus rebuildIndexCompletely(SubMonitor monitor) throws CorruptIndexException, LockObtainFailedException, - IOException, CoreException { + IOException, CoreException { MultiStatus multiStatus = new MultiStatus(TasksIndexCore.ID_PLUGIN, 0, null, null); @@ -1216,7 +1207,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL writer = createIndexWriter(true); } catch (CorruptIndexException e) { if (directory instanceof FSDirectory) { - cleanDirectory(((FSDirectory) directory).getFile()); + cleanDirectory(((FSDirectory) directory).getDirectory()); writer = createIndexWriter(true); } else { throw e; @@ -1264,7 +1255,9 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL protected IndexWriter createIndexWriter(boolean create) throws CorruptIndexException, LockObtainFailedException, IOException { - return new IndexWriter(directory, TaskAnalyzer.instance(), create, IndexWriter.MaxFieldLength.UNLIMITED); + IndexWriterConfig writerConfig = new IndexWriterConfig(Version.LATEST, TaskAnalyzer.instance()); + writerConfig.setInfoStream(InfoStream.NO_OUTPUT); + return new IndexWriter(directory, writerConfig); } /** @@ -1283,8 +1276,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL Document document = new Document(); - document.add(new Field(FIELD_IDENTIFIER.getIndexKey(), task.getHandleIdentifier(), Store.YES, - org.apache.lucene.document.Field.Index.ANALYZED)); + document.add(new TextField(FIELD_IDENTIFIER.getIndexKey(), task.getHandleIdentifier(), Store.YES)); if (taskData == null) { if ("local".equals(((AbstractTask) task).getConnectorKind())) { //$NON-NLS-1$ addIndexedAttributes(document, task);