Search returns not expected results


#1

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

is there something we do wrong?

Thank you for your help

Gérald


#2

That won’t work.

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:

$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.


#3

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

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


#4

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


#5

If I understand well your link 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?


#6

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


#7

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();
}

}


#8

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


#9

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

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

#10

@gsalin

It works perfectly for myself.

https://github.com/creecros/Creecros_Filter_Pack/tree/DateWithNull

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

e.g. date_withnull:<=today


#11

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


#12

I can include it if you so desire.


#13

It would be nice if you could include it.

Thank you

Gérald

Gérald Salin


#14

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


#15

@gsalin

Whenever fred merges, it will be available for update.