Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);

Back to the top