You are browsing documentation for version 5.0 of OroCommerce, OroCRM, and OroPlatform, maintained until August 2024 and supported until March 2026. See version 5.1 (the latest LTS version) of the Oro documentation for information on latest features.

See our Release Process documentation for more information on the currently supported and upcoming releases.

Query Builder

To perform search queries, you need to use the query builder => \Oro\Bundle\SearchBundle\Query\Query.


$query = (new Query())
        ->andWhere('all_data', '=', 'Functions', 'text')
        ->orWhere('price', '>', 85, 'decimal');

The syntax of Query builder is close to Doctrine 2.

  • select() - accepts a string or array of strings representing field names in the search index. The values of those fields will be returned in the selected_data key of the response items. The select() parser will also accept SQL field name aliasing syntax, for example:
$query = (new Query())
        ->select('fieldvalue as name')

NOTE: If you do not want to overwrite the existing fields, use the addSelect() method. * from() - takes an array or string of entity aliases to search from. If the argument was *, then the search will be performed for all entities.

  • andWhere(), orWhere() - functions set AND WHERE and OR WHERE functions in search request.
    • First argument - field name to search from. It can be set to * for searching by all fields.
    • Second argument - operators <, >, =, !=, etc. This parameter will be ignored if the first argument is for the text field.
    • Third argument - value to search
    • Fourth argument - field type.
  • setFirstResult() - set the first result offset
  • setMaxResults() - set max results of records in result.

As the result of the query, Oro\Bundle\SearchBundle\Query\Result will be returned with the information about the search query and result items.