K-Phoen / rulerz

Powerful implementation of the Specification pattern in PHP
MIT License
872 stars 97 forks source link

Find a text into an array #81

Closed DamienP33 closed 7 years ago

DamienP33 commented 7 years ago

Hello, Impossible to find text in the table, but with Elastica is OK.

With Elastica :

        $repository = $this->get('fos_elastica.finder.app.user');
        $boolQuery = new \Elastica\Query\BoolQuery();

        $fieldQuery = new \Elastica\Query\Match();
        $fieldQuery->setFieldQuery('list.text', 'foo');
        $boolQuery->addShould($fieldQuery);

        $data = $repository->find($boolQuery);

With RulerZ :

       $rulerZ = $this->get('rulerz');
        $params = ['text' => 'foo'];
        $data = $rulerZ->filter($repository, 'list.text = :text', $params);

With RulerZ, I got no result.

But, with a number is OK:

        $rulerZ = $this->get('rulerz');
        $params = ['number' => 2];
        $data = $rulerZ->filter($repository, 'list.number > :number', $params)

Did I miss something ?

K-Phoen commented 7 years ago

As you can see here, the = operator maps to the term elasticsearch query type. Depending on your data and ES mapping, this might not be the operator you want to use.

DamienP33 commented 7 years ago

With LIKE operator is OK

I tried several cases and I get strange results :

$r = $rulerZ->filter($repository, 'list.number = :number', ['number' => 100]); // OK
$r = $rulerZ->filter($repository, 'list.number >= 12'); // OK
$r = $rulerZ->filter($repository, 'list.id = "7a9f44092f7c37ab9fef87344e866eb7"'); // OK
$r = $rulerZ->filter($repository, 'list.text = "foo"'); // KO
$r = $rulerZ->filter($repository, "list.text like foo"); // OK
$r = $rulerZ->filter($repository, "list.text like :text", ['text' => 'foo']); // KO
$r = $rulerZ->filter($repository, "firstName = :name", ['name' => "Damien"]); // KO
$r = $rulerZ->filter($repository, "firstName like :name", ['name' => "Damien"]); // KO
$r = $rulerZ->filter($repository, "firstName like Damien"); // OK
$r = $rulerZ->filter($repository, "firstName = 'Damien'"); // KO
$r = $rulerZ->filter($repository, "id = '1ab73ebef97b37e8bcf49307dcf49a88'" ); // OK
$r = $rulerZ->filter($repository, "id like 1ab73ebef97b37e8bcf49307dcf49a88" ); // KO

I begin on Elastic, but is this normal ?

K-Phoen commented 7 years ago

If I take the following example:

$r = $rulerZ->filter($repository, "firstName like Damien"); // OK
$r = $rulerZ->filter($repository, "firstName = 'Damien'"); // KO

The behavior does not seem strange to me. Depending on how you configured your mapping, Elasticsearch might not be storing the original value ("Damien") but only the analyzed one (probably "damien"). That's why the strict comparison fails but not the other.

K-Phoen commented 7 years ago

Closing this issue as it's been inactive for months. Feel free to reopen it if needed :)