bazo
bazo

Reputation: 755

Doctrine ODM - like operator syntax

how would i go about simulating the like operator from SQL in doctrine odm?

use case: i want to find a Theme that has somewhere in the field caption string in a variable $search.

How would the query look like?

thanks for all answers

Upvotes: 6

Views: 4890

Answers (2)

some_guy
some_guy

Reputation: 390

For me, this worked:

use MongoDB\BSON\Regex;

$qb->field($field)->equals(new Regex($searchTerm));

Probably just dependencies are newer.

Upvotes: 0

TROODON
TROODON

Reputation: 1175

use MongoRegex

$qb->field($field)->equals(new \MongoRegex('/.*paliw.*/i'));

source

But i recomed use separate search engine (sphinx, Solr)

Upvotes: 18

Related Questions