diff options
author | David Green | 2011-11-10 00:04:04 +0000 |
---|---|---|
committer | David Green | 2011-11-10 00:04:53 +0000 |
commit | d6f98cd382509879ca28ebeffbe6631c8f8eaced (patch) | |
tree | 4c26c8d27c072d026a339c15b081f0df6b54251a | |
parent | 979e041083c39bb66f86ffe7366035e8b89a30bf (diff) | |
download | org.eclipse.mylyn.incubator-d6f98cd382509879ca28ebeffbe6631c8f8eaced.tar.gz org.eclipse.mylyn.incubator-d6f98cd382509879ca28ebeffbe6631c8f8eaced.tar.xz org.eclipse.mylyn.incubator-d6f98cd382509879ca28ebeffbe6631c8f8eaced.zip |
bug 191522: provide full text search functionality over task comments
https://bugs.eclipse.org/bugs/show_bug.cgi?id=191522
added repository_url as a field in the index to enable clients to search
for tasks in a specific repository.
3 files changed, 76 insertions, 5 deletions
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 06acb141..c3b73865 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 @@ -27,6 +27,7 @@ class TaskAnalyzer extends PerFieldAnalyzerWrapper { super(new StandardAnalyzer(Version.LUCENE_CURRENT));
addAnalyzer(TaskListIndex.IndexField.IDENTIFIER.fieldName(), new KeywordAnalyzer());
addAnalyzer(TaskListIndex.IndexField.TASK_KEY.fieldName(), new KeywordAnalyzer());
+ addAnalyzer(TaskListIndex.IndexField.REPOSITORY_URL.fieldName(), new KeywordAnalyzer());
}
}
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 20951b76..57343c36 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 @@ -25,7 +25,6 @@ import java.util.Map.Entry; import java.util.Set;
import java.util.logging.Logger;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.DateTools.Resolution;
import org.apache.lucene.document.Document;
@@ -92,6 +91,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL public static enum IndexField {
IDENTIFIER(false, null, false), //
TASK_KEY(false, null, false), //
+ REPOSITORY_URL(false, null, false), //
SUMMARY(true, null, false), //
CONTENT(true, null, false), //
ASSIGNEE(true, TaskAttribute.USER_ASSIGNED, false), //
@@ -414,8 +414,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL && patternString.indexOf('"') == -1) {
return new PrefixQuery(new Term(defaultField.fieldName(), patternString));
}
- QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, defaultField.fieldName(), new StandardAnalyzer(
- Version.LUCENE_CURRENT));
+ QueryParser qp = new QueryParser(Version.LUCENE_CURRENT, defaultField.fieldName(), new TaskAnalyzer());
Query q;
try {
q = qp.parse(patternString);
@@ -532,8 +531,9 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL }
private void addIndexedAttributes(Document document, ITask task, TaskAttribute root) {
- addIndexedAttribute(document, IndexField.SUMMARY, root.getMappedAttribute(TaskAttribute.SUMMARY));
addIndexedAttribute(document, IndexField.TASK_KEY, task.getTaskKey());
+ addIndexedAttribute(document, IndexField.REPOSITORY_URL, task.getRepositoryUrl());
+ addIndexedAttribute(document, IndexField.SUMMARY, root.getMappedAttribute(TaskAttribute.SUMMARY));
addIndexedAttribute(document, IndexField.CONTENT, root.getMappedAttribute(TaskAttribute.SUMMARY));
addIndexedAttribute(document, IndexField.CONTENT, root.getMappedAttribute(TaskAttribute.DESCRIPTION));
addIndexedAttribute(document, IndexField.CONTENT, root.getAttribute("status_whiteboard")); //$NON-NLS-1$
@@ -570,8 +570,9 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL }
private void addIndexedAttributes(Document document, ITask task) {
- addIndexedAttribute(document, IndexField.SUMMARY, task.getSummary());
addIndexedAttribute(document, IndexField.TASK_KEY, task.getTaskKey());
+ addIndexedAttribute(document, IndexField.REPOSITORY_URL, task.getRepositoryUrl());
+ addIndexedAttribute(document, IndexField.SUMMARY, task.getSummary());
addIndexedAttribute(document, IndexField.CONTENT, task.getSummary());
addIndexedAttribute(document, IndexField.CONTENT, ((AbstractTask) task).getNotes());
addIndexedDateAttributes(document, task);
@@ -816,4 +817,18 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL return field.fieldName()
+ ":[" + DateTools.dateToString(lowerBoundInclusive, Resolution.DAY) + " TO " + DateTools.dateToString(upperBoundInclusive, Resolution.DAY) + "]"; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
}
+
+ /**
+ * 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
+ */
+ public String escapeFieldValue(String value) {
+ // see http://lucene.apache.org/java/2_9_1/queryparsersyntax.html#Escaping%20Special%20Characters
+ String escaped = value.replaceAll("([\\+\\-\\!\\(\\)\\{\\}\\[\\]^\"~\\*\\?:\\\\]|&&|\\|\\|)", "\\\\$1"); //$NON-NLS-1$ //$NON-NLS-2$
+ return escaped;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexTest.java b/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexTest.java index 58f77db5..2be00fed 100644 --- a/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexTest.java +++ b/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexTest.java @@ -21,15 +21,20 @@ import java.io.IOException; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylyn.commons.core.DelegatingProgressMonitor;
+import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.core.LocalTask;
import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex;
import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex.IndexField;
import org.eclipse.mylyn.internal.tasks.index.core.TaskListIndex.TaskCollector;
import org.eclipse.mylyn.internal.tasks.index.tests.util.MockTestContext;
import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskMapper;
import org.junit.After;
@@ -225,4 +230,54 @@ public class TaskListIndexTest { assertTrue(index.matches(task, patternString));
}
+
+ @Test
+ public void testMatchesOnRepositoryUrl() throws Exception {
+ setupIndex();
+
+ ITask repositoryTask = context.createRepositoryTask();
+ ITask localTask = context.createLocalTask();
+
+ index.waitUntilIdle();
+
+ index.setDefaultField(IndexField.CONTENT);
+
+ TaskData taskData = context.getDataManager().getTaskData(repositoryTask);
+
+ // sanity
+ assertNotNull(taskData);
+ assertNotNull(taskData.getRepositoryUrl());
+ assertFalse(taskData.getRepositoryUrl().length() == 0);
+
+ // setup descriptions so that they will both match
+ final String content = "RepositoryUrl";
+ taskData.getRoot().getMappedAttribute(TaskAttribute.DESCRIPTION).setValue(content);
+ ((AbstractTask) localTask).setNotes(content);
+
+ context.getDataManager().putSubmittedTaskData(repositoryTask, taskData, new DelegatingProgressMonitor());
+
+ Set<ITask> changedElements = new HashSet<ITask>();
+ changedElements.add(localTask);
+ changedElements.add(repositoryTask);
+ context.getTaskList().notifyElementsChanged(changedElements);
+
+ index.waitUntilIdle();
+
+ assertTrue(index.matches(localTask, content));
+ assertTrue(index.matches(repositoryTask, content));
+
+ String repositoryUrlQuery = content + " AND " + IndexField.REPOSITORY_URL.fieldName() + ":\""
+ + index.escapeFieldValue(repositoryTask.getRepositoryUrl()) + "\"";
+ assertFalse(index.matches(localTask, repositoryUrlQuery));
+ assertTrue(index.matches(repositoryTask, repositoryUrlQuery));
+ }
+
+ @Test
+ public void testCharacterEscaping() {
+ setupIndex();
+ for (String special : new String[] { "+", "-", "&&", "||", "!", "(", ")", "{", "}", "[", "]", "^", "\"", "~",
+ "*", "?", ":", "\\" }) {
+ assertEquals("a\\" + special + "b", index.escapeFieldValue("a" + special + "b"));
+ }
+ }
}
|