private function getSynonymRewrites($storeId, $queryText, $type, $maxRewrites)
    {
        $indexName = $this->getIndexAlias($storeId);

        try {
            $analysis = $this->client->analyze(
                ['index' => $indexName, 'body' => ['text' => $queryText, 'analyzer' => $type]]
            );
        } catch (\Exception $e) {
            $analysis = ['tokens' => []];
        }

        $synonymByPositions = [];

        foreach ($analysis['tokens'] ?? [] as $token) {
            if ($token['type'] == 'SYNONYM') {
                $positionKey = sprintf('%s_%s', $token['start_offset'], $token['end_offset']);
                $token['token'] = str_replace('_', ' ', $token['token']);
                $synonymByPositions[$positionKey][] = $token;
            }
        }

        return $this->combineSynonyms($queryText, $synonymByPositions, $maxRewrites);
    }
private function getSynonymRewrites($storeId, $queryText, $type, $maxRewrites)
    {
        $indexName = $this->getIndexAlias($storeId);

        try {
            $analysis = $this->client->analyze(
                ['index' => $indexName, 'body' => ['text' => $queryText, 'analyzer' => $type]]
            );
        } catch (\Exception $e) {
            $analysis = ['tokens' => []];
        }

        $synonymByPositions = [];

        foreach ($analysis['tokens'] ?? [] as $token) {
            if ($token['type'] == 'SYNONYM') {
                $positionKey = sprintf('%s_%s', $token['start_offset'], $token['end_offset']);
                $token['token'] = str_replace('_', ' ', $token['token']);
                $synonymByPositions[$positionKey][] = $token;
            }
        }

        return $this->combineSynonyms($queryText, $synonymByPositions, $maxRewrites);
    }
private function getSynonymRewrites ( $ storeId , $ queryText , $ type , $ maxRewrites ) { $ indexName = $ this -> getIndexAlias ( $ storeId ) ; try { $ analysis = $ this -> client -> analyze ( [ 'index' => $ indexName , 'body' => [ 'text' => $ queryText , 'analyzer' => $ type ] ] ) ; } catch ( \ Exception $ e ) { $ analysis = [ 'tokens' => [ ] ] ; } $ synonymByPositions = [ ] ; foreach ( $ analysis [ 'tokens' ] ?? [ ] as $ token ) { if ( $ token [ 'type' ] == 'SYNONYM' ) { $ positionKey = sprintf ( '%s_%s' , $ token [ 'start_offset' ] , $ token [ 'end_offset' ] ) ; $ token [ 'token' ] = str_replace ( '_' , ' ' , $ token [ 'token' ] ) ; $ synonymByPositions [ $ positionKey ] [ ] = $ token ; } } return $ this -> combineSynonyms ( $ queryText , $ synonymByPositions , $ maxRewrites ) ; }
Generates all possible synonym rewrites for a store and text query.

@param integer $storeId     Store id.
@param string  $queryText   Text query.
@param string  $type        Substitution type (synonym or expansion).
@param integer $maxRewrites Max number of allowed rewrites.

@return array
Generates all possible synonym rewrites for a store and text query .