# Search returns not expected results

**URL:** <https://kanboard.discourse.group/t/search-returns-not-expected-results/65>\
**Category:** Open Discussions\
**Created:** [December 10, 2018, 1:23pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65 "2018-12-10T13:23:27Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsalin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@gsalin](https://kanboard.discourse.group/u/gsalin)\
**Post date:** [December 10, 2018, 1:23pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/1 "2018-12-10T13:23:27Z")

</div>

Hi,  
we would like to display only tasks for which due date is before today or is not set

we use the filter “due:none due:\<=today” or “due:none due:\<=2018-12-10”

but there are some tasks displayed that should not…  
e.g.  
 ![image](https://global.discourse-cdn.com/free1/uploads/kanboard1/original/1X/46e37bc9fca23535921c819858a0671c71f5d788.png)

is there something we do wrong?

Thank you for your help

Gérald

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 10, 2018, 3:01pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/2 "2018-12-10T15:01:13Z")

</div>

That won’t work.

```php
if ($this->value == "none") {
            $this->query->eq(TaskModel::TABLE.'.date_due', 0);
        } else {
            $this->query->neq(TaskModel::TABLE.'.date_due', 0);
            $this->query->notNull(TaskModel::TABLE.'.date_due');
            $this->applyDateFilter(TaskModel::TABLE.'.date_due');
        }

```

Your first query filters out every thing except those `eq` to `0`.

The next query uses the results of your first query before it beings, and then filters out every thing it found. When it gets to `neq` to `0`, and the result is nothing, the filter then shows every task as a result, including the closed tasks. The filters build on each other, they don’t combine.

You would need to build your own filter in order to filter what you want.

It would look something like:

```php
$method = $this->parseOperator();
$timestamp = $this->dateParser->getTimestampFromIsoFormat($this->value);

            if ($method !== '') { $this->db
                ->table(TaskModel::TABLE)
                ->beginOr()
                ->eq('date_due', 0)
                ->$method('date_due', $this->getTimestampFromOperator($method, $timestamp))
                ->closeOr()
                ->findAll();
            }

```

You would apply it without listing the `none`, i.e. `your_filter:<=today` and it would show all tasks less than or equal to today, or eq to 0.

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 10, 2018, 3:07pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/3 "2018-12-10T15:07:23Z")

</div>

And here is a reference, to help you understand how to add your own filter:

> **[creecros/Creecros\_Filter\_Pack](https://github.com/creecros/Creecros_Filter_Pack)**
>
> Kanboard filters. Contribute to creecros/Creecros\_Filter\_Pack development by creating an account on GitHub.

Also, if you ask, I’ll help you out.

---

<div class="post-metadata">

**Author:** ![gsalin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@gsalin](https://kanboard.discourse.group/u/gsalin)\
**Post date:** [December 10, 2018, 3:31pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/4 "2018-12-10T15:31:17Z")

</div>

Thank you for your quick answer !!  
I’ll have a look

---

<div class="post-metadata">

**Author:** ![gsalin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@gsalin](https://kanboard.discourse.group/u/gsalin)\
**Post date:** [December 10, 2018, 3:43pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/5 "2018-12-10T15:43:51Z")

</div>

If I understand well your link [creecros/Creecros\_Filter\_Pack](https://github.com/creecros/Creecros_Filter_Pack), you propose a plugin that adds new filters?

I can fork your source, add my custom filter then make a pull request?

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 10, 2018, 4:10pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/6 "2018-12-10T16:10:50Z")

</div>

Correct, but you don’t need to PR my repo. Just use my repo as a guide to make your own custom filter.

---

<div class="post-metadata">

**Author:** ![gsalin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@gsalin](https://kanboard.discourse.group/u/gsalin)\
**Post date:** [December 10, 2018, 7:07pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/7 "2018-12-10T19:07:54Z")

</div>

I tried, but without success for now.  
I created a new class DateWithNull.php (code below)  
I can call the filter with due\_with\_null:\<today

it returns tasks with date\_due=0, but also with date\_due \> today…  
I don’t understand.

I activated the logs and I can see the SQL request : SELECT \* FROM “tasks” WHERE (“date\_due” = ? OR “date\_due” \< ?) (do you know how I can display the valuies for the placeholders?)  
adding an error\_log statement, I have :  
[Mon Dec 10 20:04:06.664503 2018] [:error] [pid 8396] [client 147.99.103.130:57091] Methode = lt  
[Mon Dec 10 20:04:06.664537 2018] [:error] [pid 8396] [client 147.99.103.130:57091] timestamp = 1544396400

executing the previous SQL with this timestamp returns the right tasks…

any idea to troubleshoot that?

Thank you for your help

Gérald

/\*\*

- Get search attribute
- 
- @access public
- @return string[]  
\*/  
public function getAttributes()  
{  
return array(‘due\_with\_null’);  
}

/\*\*

- Apply filter
- 
- @access public
- @return string  
\*/  
public function apply()  
{

$method = $this-\>parseOperator();  
$timestamp = $this-\>dateParser-\>getTimestampFromIsoFormat($this-\>value);  
error\_log("Methode = " . $method);  
error\_log("timestamp = " . $this-\>getTimestampFromOperator($method, $timestamp));  
if ($method !== ‘’) { $this-\>db  
-\>table(TaskModel::TABLE)  
-\>beginOr()  
-\>eq(‘date\_due’, 0)  
-\>$method(‘date\_due’, $this-\>getTimestampFromOperator($method, $timestamp))  
-\>closeOr()  
-\>findAll();  
}

}

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 10, 2018, 8:05pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/8 "2018-12-10T20:05:47Z")

</div>

send me collab and i’lll take care of it next chance i get for you

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 10, 2018, 8:23pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/9 "2018-12-10T20:23:19Z")

</div>

You’ll need to get the dateparser instance too when you initialize

```auto
$this->container->extend('taskLexer', function($taskLexer, $c) {
            $taskLexer->withFilter(DateWithNull::getInstance()->setDatabase($c['db'])
                                                              ->setDateParser($c['dateParser']));
            return $taskLexer;
        });

```

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 10, 2018, 10:26pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/10 "2018-12-10T22:26:16Z")

</div>

@gsalin

It works perfectly for myself.

[https://github.com/creecros/Creecros\_Filter\_Pack/tree/DateWithNull](https://github.com/creecros/Creecros_Filter_Pack/tree/DateWithNull)

it’s on a branch, so don’t use master

e.g. `date_withnull:<=today`

---

<div class="post-metadata">

**Author:** ![gsalin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@gsalin](https://kanboard.discourse.group/u/gsalin)\
**Post date:** [December 11, 2018, 4:36am UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/11 "2018-12-11T04:36:13Z")

</div>

Hi Creecros,  
indeed, it works well with your code, I didn’t includ a return statement in the apply function before.  
thank you very much!!  
Will you include this filter in you plugin?

Thank you again!!

Gérald

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 11, 2018, 3:07pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/12 "2018-12-11T15:07:49Z")

</div>

I can include it if you so desire.

---

<div class="post-metadata">

**Author:** ![gsalin](https://avatars.discourse-cdn.com/v4/letter/g/8c91f0/32.png) [@gsalin](https://kanboard.discourse.group/u/gsalin)\
**Post date:** [December 11, 2018, 3:20pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/13 "2018-12-11T15:20:46Z")

</div>

It would be nice if you could include it.

Thank you

Gérald

Gérald Salin

![](https://global.discourse-cdn.com/free1/uploads/kanboard1/original/1X/f464dd1c7c382c015b3fc53eebe1cd1aadffee61.jpeg)

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 11, 2018, 3:26pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/14 "2018-12-11T15:26:31Z")

</div>

Next chance I get to make a new release and update readme.

---

<div class="post-metadata">

**Author:** ![creecros](https://yyz2.discourse-cdn.com/free1/user_avatar/kanboard.discourse.group/creecros/32/156_2.png) [@creecros](https://kanboard.discourse.group/u/creecros)\
**Post date:** [December 11, 2018, 3:45pm UTC](https://kanboard.discourse.group/t/search-returns-not-expected-results/65/15 "2018-12-11T15:45:01Z")

</div>

@gsalin

> <https://github.com/kanboard/website/pull/114>

Whenever fred merges, it will be available for update.
