API Reference / API Parameters / advancedSyntax
Type: boolean
Engine default: false
Parameter syntax
'advancedSyntax' => true|false

Can be used in these methods:

About this parameter

Enables the advanced query syntax.

The advanced query syntax parameter introduces two advancedSyntaxFeatures:

  • Exact phrase: only return records that match the exact words you put in double quotes ("). For example, the query "search engine" will only return records if the exact phrase “search engine” appears in at least one of the record’s attributes.

    Typo tolerance doesn’t apply to a phrase within quotes.

  • Word exclusion: to exclude records that contain a specific word. To exclude a word, prefix it with a minus (-). A minus (-) within double quotes (") isn’t treated as an excluded word.

    For example:

    • search -engine matches records containing “search” but not “engine”
    • search-engine matches records containing “search” and “engine” (word exclusion isn’t applied)
    • -search matches every record except those containing “search”
    • -search engine matches records containing “engine” but not “search”
    • "-engine" matches records containing “-engine” (word exclusion isn’t applied).

    Algolia doesn’t have a wildcard search feature where a character such as * represents one or more unknown characters. You can achieve similar results with:

    • Partial word matching for records that start with the query characters. For example, the query “foo” will find records that contain words like “food”, “fool”, “foot”, and so on.
    • Empty queries retrieve all records that match other parameters (most likely, a filter).

Examples

Enable advanced syntax by default

1
2
3
$index->setSettings([
  'advancedSyntax' => true
]);
1
2
3
$results = $index->search('query', [
  'advancedSyntax' => true
]);
Did you find this page helpful?