summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaxsun McCarthy Huggan2017-06-20 18:36:28 -0400
committerJaxsun McCarthy Huggan2017-06-20 19:33:10 -0400
commit3903deed2e964f8e650a588ea5472fdcb765bee0 (patch)
treedfbf2d72f8dbdd24fd624135f3e62cfbb8287fb9
parent1b0cf590566558e26da4515a1cf700ae700f5e48 (diff)
downloadorg.eclipse.mylyn.tasks-3903deed2e964f8e650a588ea5472fdcb765bee0.tar.gz
org.eclipse.mylyn.tasks-3903deed2e964f8e650a588ea5472fdcb765bee0.tar.xz
org.eclipse.mylyn.tasks-3903deed2e964f8e650a588ea5472fdcb765bee0.zip
518536: TaskListIndex respects all submitted query terms
Change-Id: If058bfb65718e15370b9f569d30125c709b22208 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=518536
-rw-r--r--org.eclipse.mylyn.tasks.index.core/src/org/eclipse/mylyn/internal/tasks/index/core/TaskListIndex.java21
-rw-r--r--org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexTest.java52
2 files changed, 64 insertions, 9 deletions
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 91f5d62c3..646e3f708 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
@@ -719,13 +719,12 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
for (BooleanClause clause : query.clauses()) {
if (clause.getQuery() instanceof TermQuery) {
TermQuery termQuery = (TermQuery) clause.getQuery();
- clause = new BooleanClause(new PrefixQuery(termQuery.getTerm()), clause.getOccur());
- qb.add(clause);
- }
- if (!hasBooleanSpecifiers) {
+ clause = new BooleanClause(new PrefixQuery(termQuery.getTerm()),
+ computeOccur(clause, hasBooleanSpecifiers));
+ } else if (!hasBooleanSpecifiers) {
clause = new BooleanClause(clause.getQuery(), Occur.MUST);
- qb.add(clause);
}
+ qb.add(clause);
}
q = qb.build();
} else if (q instanceof TermQuery) {
@@ -734,6 +733,13 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
return q;
}
+ private Occur computeOccur(BooleanClause clause, boolean hasBooleanSpecifiers) {
+ if (!hasBooleanSpecifiers) {
+ return Occur.MUST;
+ }
+ return clause.getOccur();
+ }
+
private boolean containsSpecialCharacters(String patternString) {
return patternString.indexOf(':') >= 0 || patternString.indexOf('"') >= 0 || patternString.indexOf('*') >= 0
|| patternString.indexOf('?') >= 0;
@@ -966,8 +972,9 @@ public class TaskListIndex implements ITaskDataManagerListener, ITaskListChangeL
}
if (isPersonField(indexField)) {
- IRepositoryPerson repositoryPerson = attribute.getTaskData().getAttributeMapper().getRepositoryPerson(
- attribute);
+ IRepositoryPerson repositoryPerson = attribute.getTaskData()
+ .getAttributeMapper()
+ .getRepositoryPerson(attribute);
addIndexedAttribute(document, indexField, repositoryPerson);
if (values.size() <= 1) {
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 89cc805b7..f458b3dc5 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
@@ -120,12 +120,15 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest {
index.setDefaultField(TaskListIndex.FIELD_CONTENT);
- assertTrue(index.matches(task, task.getSummary()));
+ String summary = task.getSummary();
+ assertTrue(index.matches(task, summary));
+ assertTrue(index.matches(task, summary.substring(0, summary.length() - 3) + "*"));
assertFalse(index.matches(task, "" + System.currentTimeMillis()));
index.setDefaultField(FIELD_SUMMARY);
- assertTrue(index.matches(task, task.getSummary()));
+ assertTrue(index.matches(task, summary));
+ assertTrue(index.matches(task, summary.substring(0, summary.length() - 3) + "*"));
assertFalse(index.matches(task, "" + System.currentTimeMillis()));
}
@@ -626,6 +629,51 @@ public class TaskListIndexTest extends AbstractTaskListIndexTest {
TaskListIndex.FIELD_ATTACHMENT_NAME.getIndexKey() + ":\"" + attachmentMapper.getDescription() + "\""));
}
+ @Test
+ public void testFindWithComplexQuery() throws Exception {
+ setupIndex();
+
+ ITask task1 = context.createRepositoryTask();
+ setSummary(task1, "one two three");
+ ITask task2 = context.createRepositoryTask();
+ setSummary(task2, "two three four");
+ ITask task3 = context.createRepositoryTask();
+ setSummary(task3, "three four five");
+
+ String repositoryUrl = task1.getRepositoryUrl();
+ assertEquals(repositoryUrl, task2.getRepositoryUrl());
+ assertEquals(repositoryUrl, task3.getRepositoryUrl());
+ repositoryUrl = index.escapeFieldValue(repositoryUrl);
+
+ index.reindex();
+ index.waitUntilIdle();
+ index.setDefaultField(TaskListIndex.FIELD_CONTENT);
+
+ String pattern = "repository_url:%s AND (summary:%s* OR task_key:%s)";
+ String query = String.format(pattern, repositoryUrl, "five", task1.getTaskKey());
+ assertTrue(index.matches(task1, query));
+ assertFalse(index.matches(task2, query));
+ assertTrue(index.matches(task3, query));
+
+ query = String.format(pattern, repositoryUrl, task2.getTaskKey(), task2.getTaskKey());
+ assertFalse(index.matches(task1, query));
+ assertTrue(index.matches(task2, query));
+ assertFalse(index.matches(task3, query));
+
+ query = String.format(pattern, repositoryUrl, "two", "something.irrelevant");
+ assertTrue(index.matches(task1, query));
+ assertTrue(index.matches(task2, query));
+ assertFalse(index.matches(task3, query));
+ }
+
+ private void setSummary(ITask task, String summary) throws CoreException {
+ task.setSummary(summary);
+ TaskData taskData = context.getDataManager().getTaskData(task);
+ taskData.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).setValue(summary);
+ context.getDataManager().putSubmittedTaskData(task, taskData, new DelegatingProgressMonitor());
+ context.getTaskList().notifyElementsChanged(Collections.singleton(task));
+ }
+
private void assertCanFindTask(ITask task) {
TestTaskCollector collector = new TestTaskCollector();
index.find(task.getSummary(), collector, 1000);