From b73943da5b5d8291c6035c74e4af59df224bd333 Mon Sep 17 00:00:00 2001 From: Christian Tam Date: Fri, 20 Jan 2017 16:25:28 -0700 Subject: 389960: task list indexer now indexes private notes Change-Id: I13568107e61c553250c5efe093f735cce03a75d4 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=389960 Signed-off-by: Christian Tam --- .../mylyn/internal/tasks/index/core/Messages.java | 2 + .../internal/tasks/index/core/TaskListIndex.java | 10 ++ .../internal/tasks/index/core/messages.properties | 1 + .../tasks/index/tests/TaskListIndexTest.java | 185 ++++++++++++++++++--- 4 files changed, 178 insertions(+), 20 deletions(-) diff --git a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/Messages.java b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/Messages.java index 048c931d4..18e339c89 100644 --- a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/Messages.java +++ b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/Messages.java @@ -18,6 +18,8 @@ import org.eclipse.osgi.util.NLS; class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.tasks.index.core.messages"; //$NON-NLS-1$ + public static String TaskListIndex_field_notes; + public static String TaskListIndex_field_attachment; public static String TaskListIndex_field_content; 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 ac16533ed..38dcd9a7d 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 @@ -131,6 +131,8 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL private static final String TASK_ATTRIBUTE_ATTACHMENT_NAME = INDEX_TASK_ATTRIBUTE_PREFIX + "attachment"; //$NON-NLS-1$ + private static final String TASK_ATTRIBUTE_NOTES = INDEX_TASK_ATTRIBUTE_PREFIX + "notes"; //$NON-NLS-1$ + public static final org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field FIELD_IDENTIFIER = new AbstractTaskSchema.Field( TASK_ATTRIBUTE_IDENTIFIER, Messages.TaskListIndex_field_identifier, TaskAttribute.TYPE_SHORT_TEXT, "identifier"); //$NON-NLS-1$ @@ -155,6 +157,9 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL TASK_ATTRIBUTE_ATTACHMENT_NAME, Messages.TaskListIndex_field_attachment, TaskAttribute.TYPE_SHORT_TEXT, "attachment"); //$NON-NLS-1$ + public static final org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field FIELD_NOTES = new AbstractTaskSchema.Field( + TASK_ATTRIBUTE_NOTES, Messages.TaskListIndex_field_notes, TaskAttribute.TYPE_LONG_TEXT, "notes"); //$NON-NLS-1$ + private class MaintainIndexJob extends Job { public MaintainIndexJob() { @@ -203,6 +208,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL specialFields.add(FIELD_PERSON); specialFields.add(FIELD_TASK_KEY); specialFields.add(FIELD_ATTACHMENT_NAME); + specialFields.add(FIELD_NOTES); addIndexedField(FIELD_IDENTIFIER); addIndexedField(FIELD_TASK_KEY); @@ -224,6 +230,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL addIndexedField(DefaultTaskSchema.getInstance().RESOLUTION); addIndexedField(DefaultTaskSchema.getInstance().SEVERITY); addIndexedField(DefaultTaskSchema.getInstance().STATUS); + addIndexedField(FIELD_NOTES); } private static enum MaintainIndexType { @@ -845,6 +852,8 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL addIndexedAttribute(document, FIELD_TASK_KEY, task.getTaskKey()); addIndexedAttribute(document, FIELD_REPOSITORY_URL, task.getRepositoryUrl()); addIndexedAttribute(document, FIELD_SUMMARY, root.getMappedAttribute(TaskAttribute.SUMMARY)); + addIndexedAttribute(document, FIELD_CONTENT, ((AbstractTask) task).getNotes()); + addIndexedAttribute(document, FIELD_NOTES, ((AbstractTask) task).getNotes()); for (TaskAttribute contentAttribute : computeContentAttributes(root)) { addIndexedAttribute(document, FIELD_CONTENT, contentAttribute); @@ -936,6 +945,7 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL addIndexedAttribute(document, FIELD_SUMMARY, task.getSummary()); addIndexedAttribute(document, FIELD_CONTENT, task.getSummary()); addIndexedAttribute(document, FIELD_CONTENT, ((AbstractTask) task).getNotes()); + addIndexedAttribute(document, FIELD_NOTES, ((AbstractTask) task).getNotes()); addIndexedDateAttributes(document, task); } diff --git a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/messages.properties b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/messages.properties index aa751acb0..2214317fb 100644 --- a/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/messages.properties +++ b/org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/messages.properties @@ -15,3 +15,4 @@ TaskListIndex_task_rebuilding_index=Indexing tasks TaskListIndex_field_identifier=Identifier TaskListIndex_field_person=Person TaskListIndex_field_repository_url=Repository URL +TaskListIndex_field_notes=Notes \ No newline at end of file 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 22f6e4466..89cc805b7 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 @@ -11,9 +11,9 @@ package org.eclipse.mylyn.internal.tasks.index.tests; -import static junit.framework.Assert.assertEquals; import static org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.createTempFolder; import static org.eclipse.mylyn.commons.sdk.util.CommonTestUtil.deleteFolderRecursively; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -34,8 +34,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; -import junit.framework.Assert; - import org.eclipse.core.runtime.CoreException; import org.eclipse.mylyn.commons.core.DelegatingProgressMonitor; import org.eclipse.mylyn.internal.tasks.core.AbstractTask; @@ -55,9 +53,11 @@ import org.junit.Test; */ public class TaskListIndexTest extends AbstractTaskListIndexTest { - private static final org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field FIELD_SUMMARY = DefaultTaskSchema.getInstance().SUMMARY; + private static final org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field FIELD_SUMMARY = DefaultTaskSchema + .getInstance().SUMMARY; - private static final org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field FIELD_DATE_CREATION = DefaultTaskSchema.getInstance().DATE_CREATION; + private static final org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field FIELD_DATE_CREATION = DefaultTaskSchema + .getInstance().DATE_CREATION; private static class TestTaskCollector extends TaskCollector { @@ -252,13 +252,12 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest { + index.escapeFieldValue(taskData.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).getValue()) + "\""; - assertTrue(index.matches(repositoryTask, TaskListIndex.FIELD_TASK_KEY.getIndexKey() + ":" + taskKey - + querySuffix)); + assertTrue(index.matches(repositoryTask, + TaskListIndex.FIELD_TASK_KEY.getIndexKey() + ":" + taskKey + querySuffix)); // does not match on task key prefix - assertTrue(index.matches(repositoryTask, - TaskListIndex.FIELD_TASK_KEY.getIndexKey() + ":" + taskKey.substring(0, taskKey.length() - 1) - + querySuffix)); + assertTrue(index.matches(repositoryTask, TaskListIndex.FIELD_TASK_KEY.getIndexKey() + ":" + + taskKey.substring(0, taskKey.length() - 1) + querySuffix)); } @Test @@ -296,6 +295,154 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest { assertFalse(index.matches(task, "one AND four")); } + @Test + public void testMatchesNotesWithExpectedQueryBehaviourWithRepositoryTask() + throws InterruptedException, CoreException { + setupIndex(); + + ITask task = context.createRepositoryTask(); + ((AbstractTask) task).setNotes("one two three"); + + index.reindex(); + index.waitUntilIdle(); + + index.setDefaultField(TaskListIndex.FIELD_NOTES); + + // default search (without logical operators) + assertFalse(index.matches(task, "asdf")); + assertTrue(index.matches(task, "one")); + assertTrue(index.matches(task, "two")); + assertTrue(index.matches(task, "three")); + assertTrue(index.matches(task, "thr")); + assertTrue(index.matches(task, "one two")); + assertTrue(index.matches(task, "one three")); + + // wildcard search should not match multiple terms separated by whitespace + assertFalse(index.matches(task, "one*three")); + + // wildcard search should match multiple characters in a single term + assertTrue(index.matches(task, "t*ee")); + + // logical operator makes it work with multiple terms + assertTrue(index.matches(task, "one AND three")); + assertTrue(index.matches(task, "one OR three")); + assertTrue(index.matches(task, "one AND thr")); + + // logical operator requiring a non-existant term should not match + assertFalse(index.matches(task, "one AND four")); + } + + @Test + public void testMatchesNotesWithExpectedQueryBehaviourWithLocalTask() throws InterruptedException, CoreException { + setupIndex(); + + ITask task = context.createLocalTask(); + ((AbstractTask) task).setNotes("one two three"); + + context.getTaskList().notifyElementsChanged(Collections.singleton(task)); + + index.waitUntilIdle(); + + index.setDefaultField(TaskListIndex.FIELD_NOTES); + + // default search (without logical operators) + assertFalse(index.matches(task, "asdf")); + assertTrue(index.matches(task, "one")); + assertTrue(index.matches(task, "two")); + assertTrue(index.matches(task, "three")); + assertTrue(index.matches(task, "thr")); + assertTrue(index.matches(task, "one two")); + assertTrue(index.matches(task, "one three")); + + // wildcard search should not match multiple terms separated by whitespace + assertFalse(index.matches(task, "one*three")); + + // wildcard search should match multiple characters in a single term + assertTrue(index.matches(task, "t*ee")); + + // logical operator makes it work with multiple terms + assertTrue(index.matches(task, "one AND three")); + assertTrue(index.matches(task, "one OR three")); + assertTrue(index.matches(task, "one AND thr")); + + // logical operator requiring a non-existant term should not match + assertFalse(index.matches(task, "one AND four")); + } + + @Test + public void testMatchesContentWithExpectedQueryBehaviourWithRepositoryTask() + throws InterruptedException, CoreException { + setupIndex(); + + ITask task = context.createRepositoryTask(); + ((AbstractTask) task).setNotes("one two three"); + + index.reindex(); + index.waitUntilIdle(); + + index.setDefaultField(TaskListIndex.FIELD_CONTENT); + + // default search (without logical operators) + assertFalse(index.matches(task, "asdf")); + assertTrue(index.matches(task, "one")); + assertTrue(index.matches(task, "two")); + assertTrue(index.matches(task, "three")); + assertTrue(index.matches(task, "thr")); + assertTrue(index.matches(task, "one two")); + assertTrue(index.matches(task, "one three")); + + // wildcard search should not match multiple terms separated by whitespace + assertFalse(index.matches(task, "one*three")); + + // wildcard search should match multiple characters in a single term + assertTrue(index.matches(task, "t*ee")); + + // logical operator makes it work with multiple terms + assertTrue(index.matches(task, "one AND three")); + assertTrue(index.matches(task, "one OR three")); + assertTrue(index.matches(task, "one AND thr")); + + // logical operator requiring a non-existant term should not match + assertFalse(index.matches(task, "one AND four")); + } + + @Test + public void testMatchesContentWithExpectedQueryBehaviourWithLocalTask() throws InterruptedException, CoreException { + setupIndex(); + + ITask task = context.createLocalTask(); + ((AbstractTask) task).setNotes("one two three"); + + context.getTaskList().notifyElementsChanged(Collections.singleton(task)); + + index.waitUntilIdle(); + + index.setDefaultField(TaskListIndex.FIELD_CONTENT); + + // default search (without logical operators) + assertFalse(index.matches(task, "asdf")); + assertTrue(index.matches(task, "one")); + assertTrue(index.matches(task, "two")); + assertTrue(index.matches(task, "three")); + assertTrue(index.matches(task, "thr")); + assertTrue(index.matches(task, "one two")); + assertTrue(index.matches(task, "one three")); + + // wildcard search should not match multiple terms separated by whitespace + assertFalse(index.matches(task, "one*three")); + + // wildcard search should match multiple characters in a single term + assertTrue(index.matches(task, "t*ee")); + + // logical operator makes it work with multiple terms + assertTrue(index.matches(task, "one AND three")); + assertTrue(index.matches(task, "one OR three")); + assertTrue(index.matches(task, "one AND thr")); + + // logical operator requiring a non-existant term should not match + assertFalse(index.matches(task, "one AND four")); + } + @Test public void testCharacterEscaping() { setupIndex(); @@ -390,7 +537,7 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest { for (Future future : futures) { assertEquals(Boolean.TRUE, future.get()); } - Assert.assertEquals(nThreads, concurrencyLevel[0]); + assertEquals(nThreads, concurrencyLevel[0]); } finally { executorService.shutdownNow(); } @@ -409,14 +556,12 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest { context.refactorMockRepositoryUrl(newUrl); - Assert.assertFalse(originalHandle.equals(repositoryTask.getHandleIdentifier())); + assertFalse(originalHandle.equals(repositoryTask.getHandleIdentifier())); index.waitUntilIdle(); - Assert.assertTrue(index.matches( - repositoryTask, - TaskListIndex.FIELD_IDENTIFIER.getIndexKey() + ":" - + index.escapeFieldValue(repositoryTask.getHandleIdentifier()))); + assertTrue(index.matches(repositoryTask, TaskListIndex.FIELD_IDENTIFIER.getIndexKey() + ":" + + index.escapeFieldValue(repositoryTask.getHandleIdentifier()))); } @Test @@ -473,12 +618,12 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest { index.waitUntilIdle(); assertTrue(index.matches(repositoryTask, "\"" + attachmentMapper.getDescription() + "\"")); - assertTrue(index.matches(repositoryTask, TaskListIndex.FIELD_ATTACHMENT_NAME.getIndexKey() + ":\"" - + attachmentMapper.getFileName() + "\"")); + assertTrue(index.matches(repositoryTask, + TaskListIndex.FIELD_ATTACHMENT_NAME.getIndexKey() + ":\"" + attachmentMapper.getFileName() + "\"")); assertFalse(index.matches(repositoryTask, TaskListIndex.FIELD_CONTENT.getIndexKey() + ":\"" + attachmentMapper.getFileName() + "\"")); - assertFalse(index.matches(repositoryTask, TaskListIndex.FIELD_ATTACHMENT_NAME.getIndexKey() + ":\"" - + attachmentMapper.getDescription() + "\"")); + assertFalse(index.matches(repositoryTask, + TaskListIndex.FIELD_ATTACHMENT_NAME.getIndexKey() + ":\"" + attachmentMapper.getDescription() + "\"")); } private void assertCanFindTask(ITask task) { -- cgit v1.2.3