summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-04 18:01:42 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-04 18:01:42 -0400
commit32ddfb3fba9e0726623addd48ccd7af69e3b44f0 (patch)
tree2137a21d4703820adc4c9589bb2140df9849755f
parent198f3eda90807c0295a013cd4ebdc3806545d608 (diff)
Allow search by task id
-rw-r--r--app/Core/Lexer.php1
-rw-r--r--app/Model/TaskFilter.php13
-rw-r--r--docs/search.markdown6
-rw-r--r--tests/units/LexerTest.php5
-rw-r--r--tests/units/TaskFilterTest.php41
5 files changed, 64 insertions, 2 deletions
diff --git a/app/Core/Lexer.php b/app/Core/Lexer.php
index f6978bbd..3887dc82 100644
--- a/app/Core/Lexer.php
+++ b/app/Core/Lexer.php
@@ -40,6 +40,7 @@ class Lexer
'/^(yesterday|tomorrow|today)/' => 'T_DATE',
'/^("(.*?)")/' => 'T_STRING',
"/^(\w+)/" => 'T_STRING',
+ "/^(#\d+)/" => 'T_STRING',
);
/**
diff --git a/app/Model/TaskFilter.php b/app/Model/TaskFilter.php
index 0bac3f46..c88be830 100644
--- a/app/Model/TaskFilter.php
+++ b/app/Model/TaskFilter.php
@@ -173,7 +173,7 @@ class TaskFilter extends Base
}
/**
- * Filter by title
+ * Filter by title or id if the string is like #123 or an integer
*
* @access public
* @param string $title
@@ -181,7 +181,16 @@ class TaskFilter extends Base
*/
public function filterByTitle($title)
{
- $this->query->ilike(Task::TABLE.'.title', '%'.$title.'%');
+ if (strlen($title) > 1 && $title{0} === '#' && ctype_digit(substr($title, 1))) {
+ $this->query->eq(Task::TABLE.'.id', substr($title, 1));
+ }
+ else if (ctype_digit($title)) {
+ $this->query->eq(Task::TABLE.'.id', $title);
+ }
+ else {
+ $this->query->ilike(Task::TABLE.'.title', '%'.$title.'%');
+ }
+
return $this;
}
diff --git a/docs/search.markdown b/docs/search.markdown
index 99b76393..3d00b158 100644
--- a/docs/search.markdown
+++ b/docs/search.markdown
@@ -12,6 +12,12 @@ This example will returns all tasks assigned to me with a due date for tomorrow
assigne:me due:tomorrow my title
```
+Search by task id or title
+--------------------------
+
+- Search by task id: `#123` or `123`
+- Search by task title: anything that don't match any search attributes mentioned below
+
Search by status
----------------
diff --git a/tests/units/LexerTest.php b/tests/units/LexerTest.php
index 0e3a61ae..bf0ffdd0 100644
--- a/tests/units/LexerTest.php
+++ b/tests/units/LexerTest.php
@@ -341,6 +341,11 @@ class LexerTest extends Base
);
$this->assertEquals(
+ array('T_TITLE' => '#123'),
+ $lexer->map($lexer->tokenize('#123'))
+ );
+
+ $this->assertEquals(
array(),
$lexer->map($lexer->tokenize('color:assignee:'))
);
diff --git a/tests/units/TaskFilterTest.php b/tests/units/TaskFilterTest.php
index 6a48f194..af00b6fa 100644
--- a/tests/units/TaskFilterTest.php
+++ b/tests/units/TaskFilterTest.php
@@ -27,6 +27,47 @@ class TaskFilterTest extends Base
$this->assertEmpty($tf->search('search something')->findAll());
}
+ public function testSearchById()
+ {
+ $p = new Project($this->container);
+ $tc = new TaskCreation($this->container);
+ $tf = new TaskFilter($this->container);
+
+ $this->assertEquals(1, $p->create(array('name' => 'test')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task1')));
+ $this->assertNotFalse($tc->create(array('project_id' => 1, 'title' => 'task2')));
+
+ $tf->search('#2');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('task2', $tasks[0]['title']);
+
+ $tf->search('1');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('task1', $tasks[0]['title']);
+
+ $tf->search('something');
+ $tasks = $tf->findAll();
+ $this->assertEmpty($tasks);
+
+ $tf->search('#');
+ $tasks = $tf->findAll();
+ $this->assertEmpty($tasks);
+
+ $tf->search('#abcd');
+ $tasks = $tf->findAll();
+ $this->assertEmpty($tasks);
+
+ $tf->search('task1');
+ $tasks = $tf->findAll();
+ $this->assertNotEmpty($tasks);
+ $this->assertCount(1, $tasks);
+ $this->assertEquals('task1', $tasks[0]['title']);
+ }
+
public function testSearchWithReference()
{
$p = new Project($this->container);