1

i'm doing search with ZF2 Doctrine2 ODM and using MongoRegix but the problem is that i'm not able to search those terms which contains brackets like BS(Hons) is not searchable. my query is

$q->addOr($q->expr()->field($columns[$i]['field'])->equals(new \MongoRegex('/.*BS(Hons).*/i')));

any suggestion?

  • Parantehsis are assumed to be used for Grouping in Doctrine you can check refrence http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html – noobie-php Sep 25 '13 at 14:24
  • if i m not wrong brackets () are used for the grouping in ORM, does it also implies on ODM? – Shahbaz Sep 25 '13 at 14:56

1 Answers1

2

Reserved characters can be used in MongoRegx in the way.

/.*BS/(Hons/).*/i

the Query will be like this

$q->addOr($q->expr()->field($field)->equals(new \MongoRegex('/.*BS/(Hons/).*/i')));
Shahbaz
  • 3,433
  • 1
  • 26
  • 43