3liz / lizmap-cadastre-module

Module Cadastre for Lizmap Web Client
Mozilla Public License 2.0
4 stars 5 forks source link

Search: many notice in logs about $this->term #3

Closed laurentj closed 4 years ago

laurentj commented 4 years ago

I have many notices in my log like this one:

notice   Undefined offset: 0
  app/vendor/lizmap/lizmap-cadastre-module/cadastre/classes/search.class.php        85
 /index.php/cadastre/service/autocomplete?term=che&field=voie&commune=560140&limit=100&layer=XXXXXX&repository=XXXXXX&project=XXXXXX
 array (   'term' => 'che',   'field' => 'voie',   'commune' => '560140',   'limit' => '100',   'layer' => 'XXXXXX',   'repository' => 'XXXXXX',   'project' => 'XXXXXX',   'module'

        0       search->getSql()      app/vendor/lizmap/lizmap-cadastre-module/cadastre/classes/search.class.php : 243
        1       search->getData()       app/vendor/lizmap/lizmap-cadastre-module/cadastre/controllers/service.classic.php : 165
        2       serviceCtrl->autocomplete()    lizmap_web_client/lib/jelix/core/jCoordinator.class.php : 225
        3       jCoordinator->process() index.php : 23

It's about this code in search.class.php:

$sql = "
            SELECT DISTINCT
                v.voie AS code,
                trim(concat(
                    trim(c.tex2), ' - ',
                    Coalesce(trim(natvoi) || ' ', ''),
                    trim(libvoi)
                )) AS label,
                trim(libvoi) ~ '^" . $this->terms[0] . "' AS b
            FROM voie v
            INNER JOIN geo_commune c ON c.commune = v.commune
            WHERE 2>1
            ";

It uses the first item of $this->terms but this array can be empty. And it is empty here since the term parameter is a single word which is into the list of stop words.

What to do when $this->terms is empty? just having trim(libvoi) AS b into the query?

@mdouchin @rldhont?