MATCH Query : Access array offset on value of type null in DQL parser #6509

Open
opened 2026-01-22 15:34:18 +01:00 by admin · 9 comments
Owner

Originally created by @aguidis on GitHub (Aug 2, 2020).

Bug Report

Q A
BC no
Version v2.7.3
PHP 7.4.8

Summary

I installed the DoctrineExtensions to use the MATCH AGAINST query.

I added this clause in my repository method:

if ($name = $search->name) {
    $qb
        ->andWhere('MATCH(shop.name) AGAINST (:name BOOLEAN)')
        ->setParameter('name', $name.'*')
    ;
}

Current behavior

Notice: Trying to access array offset on value of type null

image

When the MATCH clause is parsed, the following error is triggered in the Parser because $this->lexer->lookahead is null.

image

Originally created by @aguidis on GitHub (Aug 2, 2020). ## Bug Report | Q | A | |---------|--------| | BC | no | | Version | v2.7.3 | | PHP | 7.4.8 | ## Summary I installed the [DoctrineExtensions](https://github.com/beberlei/DoctrineExtensions) to use the [**MATCH AGAINST**](https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/MatchAgainst.php) query. I added this clause in my repository method: ```php if ($name = $search->name) { $qb ->andWhere('MATCH(shop.name) AGAINST (:name BOOLEAN)') ->setParameter('name', $name.'*') ; } ``` ## Current behavior > Notice: Trying to access array offset on value of type null ![image](https://user-images.githubusercontent.com/1856652/89124139-e6e2cd00-d4d4-11ea-8077-e6e3aa934b54.png) When the `MATCH` clause is parsed, the following error is triggered in the [Parser](https://github.com/doctrine/orm/blob/2.7/lib/Doctrine/ORM/Query/Parser.php#L3323) because `$this->lexer->lookahead` is `null`. ![image](https://user-images.githubusercontent.com/1856652/89124014-f9103b80-d4d3-11ea-9290-a89a98236279.png)
Author
Owner

@beberlei commented on GitHub (Sep 13, 2020):

@greg0ire this sounds a lot like that bug we had early in 2.7 cycle, do you remember what it was?

@beberlei commented on GitHub (Sep 13, 2020): @greg0ire this sounds a lot like that bug we had early in 2.7 cycle, do you remember what it was?
Author
Owner

@greg0ire commented on GitHub (Sep 13, 2020):

@beberlei it doesn't ring a bell but I found this in the issues: https://github.com/doctrine/orm/issues/7983

@greg0ire commented on GitHub (Sep 13, 2020): @beberlei it doesn't ring a bell but I found this in the issues: https://github.com/doctrine/orm/issues/7983
Author
Owner

@bigwhoop commented on GitHub (Nov 9, 2020):

Hi. I had this error in v2.7.3 as well, but it seems to be fixed with v2.7.4.

@bigwhoop commented on GitHub (Nov 9, 2020): Hi. I had this error in v2.7.3 as well, but it seems to be fixed with v2.7.4.
Author
Owner

@greg0ire commented on GitHub (Nov 11, 2020):

@aguidis can you try upgrading?

@greg0ire commented on GitHub (Nov 11, 2020): @aguidis can you try upgrading?
Author
Owner

@Bruspashko commented on GitHub (Nov 16, 2020):

@greg0ire I'm having the same problem on 2.7.4. It's basically because Parser doesn't know how to handle Match Against. It expects a comparison operator, and nothing is passed.

@Bruspashko commented on GitHub (Nov 16, 2020): @greg0ire I'm having the same problem on 2.7.4. It's basically because Parser doesn't know how to handle Match Against. It expects a comparison operator, and nothing is passed.
Author
Owner

@bigwhoop commented on GitHub (Jan 9, 2021):

IIRC correctly the query needs to have a comparison like = 1 (or = 0 for "not matching") in boolean mode. Example:

->andWhere('MATCH(x.field) AGAINST(:value BOOLEAN) = 1')
->setParameter('value', $value)
@bigwhoop commented on GitHub (Jan 9, 2021): IIRC correctly the query needs to have a comparison like `= 1` (or `= 0` for "not matching") in boolean mode. Example: ``` ->andWhere('MATCH(x.field) AGAINST(:value BOOLEAN) = 1') ->setParameter('value', $value) ```
Author
Owner

@julkwel commented on GitHub (Jan 10, 2021):

@bigwhoop this fix the error but return no results ( i don't know if i have a mistake in this query ).

I'm sure that I have this text at column title : Lorem ipsum need to query , and my query :

$qb->createQueryBuilder('c')
->andWhere("MATCH (c.title) AGAINST(:value BOOLEAN) = 1")
->setParameter('value', 'ipsum')->getQuery()->getResults(); 

this return empty.

@julkwel commented on GitHub (Jan 10, 2021): @bigwhoop this fix the error but return no results ( i don't know if i have a mistake in this query ). I'm sure that I have this text at column `title` : ` Lorem ipsum need to query ` , and my query : ``` $qb->createQueryBuilder('c') ->andWhere("MATCH (c.title) AGAINST(:value BOOLEAN) = 1") ->setParameter('value', 'ipsum')->getQuery()->getResults(); ``` this return empty.
Author
Owner

@pgrzesiecki commented on GitHub (Nov 28, 2021):

Yes it return no data because comparing this to = 1 or = 0 this query is not valid match against query (especially in mariadb).

@pgrzesiecki commented on GitHub (Nov 28, 2021): Yes it return no data because comparing this to `= 1` or `= 0` this query is not valid `match against` query (especially in mariadb).
Author
Owner

@mklewitz commented on GitHub (Sep 2, 2022):

MATCH AGAINST doesn't simply return 0 or 1, but a score. So this will work:

MATCH (alias.fieldName) AGAINST(:searchValue BOOLEAN) > 0

You can even select the score as scalar value and/or order by the best match:

$this->createQueryBuilder('alias')
    ->addSelect('MATCH(alias.fieldName) AGAINST (:searchValue BOOLEAN)')
    ->where('MATCH(alias.fieldName) AGAINST (:searchValue BOOLEAN) > 0')
    ->orderBy('MATCH(alias.fieldName) AGAINST (:searchValue BOOLEAN)', 'DESC')
    ->setParameter('searchValue', $searchValue)
@mklewitz commented on GitHub (Sep 2, 2022): MATCH AGAINST doesn't simply return 0 or 1, but a score. So this will work: ```MATCH (alias.fieldName) AGAINST(:searchValue BOOLEAN) > 0``` You can even select the score as scalar value and/or order by the best match: ``` $this->createQueryBuilder('alias') ->addSelect('MATCH(alias.fieldName) AGAINST (:searchValue BOOLEAN)') ->where('MATCH(alias.fieldName) AGAINST (:searchValue BOOLEAN) > 0') ->orderBy('MATCH(alias.fieldName) AGAINST (:searchValue BOOLEAN)', 'DESC') ->setParameter('searchValue', $searchValue) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6509