private function combineSynonyms($queryText, $synonymByPositions, $maxRewrites, $substitutions = 0, $offset = 0)
    {
        $combinations = [];

        if (!empty($synonymByPositions) && $substitutions < $maxRewrites) {
            $currentPositionSynonyms = current($synonymByPositions);
            $remainingSynonyms = array_slice($synonymByPositions, 1);

            foreach ($currentPositionSynonyms as $synonym) {
                $startOffset = $synonym['start_offset'] + $offset;
                $length      = $synonym['end_offset'] - $synonym['start_offset'];
                $rewrittenQueryText = $this->mbSubstrReplace($queryText, $synonym['token'], $startOffset, $length);
                $newOffset = mb_strlen($rewrittenQueryText) - mb_strlen($queryText) + $offset;
                $combinations[$rewrittenQueryText] = $substitutions + 1;

                if (!empty($remainingSynonyms)) {
                    $combinations = array_merge(
                        $combinations,
                        $this->combineSynonyms($rewrittenQueryText, $remainingSynonyms, $maxRewrites, $substitutions + 1, $newOffset)
                    );
                }
            }

            if (!empty($remainingSynonyms)) {
                $combinations = array_merge(
                    $combinations,
                    $this->combineSynonyms($queryText, $remainingSynonyms, $maxRewrites, $substitutions, $offset)
                );
            }
        }

        return $combinations;
    }
private function combineSynonyms($queryText, $synonymByPositions, $maxRewrites, $substitutions = 0, $offset = 0)
    {
        $combinations = [];

        if (!empty($synonymByPositions) && $substitutions < $maxRewrites) {
            $currentPositionSynonyms = current($synonymByPositions);
            $remainingSynonyms = array_slice($synonymByPositions, 1);

            foreach ($currentPositionSynonyms as $synonym) {
                $startOffset = $synonym['start_offset'] + $offset;
                $length      = $synonym['end_offset'] - $synonym['start_offset'];
                $rewrittenQueryText = $this->mbSubstrReplace($queryText, $synonym['token'], $startOffset, $length);
                $newOffset = mb_strlen($rewrittenQueryText) - mb_strlen($queryText) + $offset;
                $combinations[$rewrittenQueryText] = $substitutions + 1;

                if (!empty($remainingSynonyms)) {
                    $combinations = array_merge(
                        $combinations,
                        $this->combineSynonyms($rewrittenQueryText, $remainingSynonyms, $maxRewrites, $substitutions + 1, $newOffset)
                    );
                }
            }

            if (!empty($remainingSynonyms)) {
                $combinations = array_merge(
                    $combinations,
                    $this->combineSynonyms($queryText, $remainingSynonyms, $maxRewrites, $substitutions, $offset)
                );
            }
        }

        return $combinations;
    }
private function combineSynonyms ( $ queryText , $ synonymByPositions , $ maxRewrites , $ substitutions = 0 , $ offset = 0 ) { $ combinations = [ ] ; if ( ! empty ( $ synonymByPositions ) && $ substitutions < $ maxRewrites ) { $ currentPositionSynonyms = current ( $ synonymByPositions ) ; $ remainingSynonyms = array_slice ( $ synonymByPositions , 1 ) ; foreach ( $ currentPositionSynonyms as $ synonym ) { $ startOffset = $ synonym [ 'start_offset' ] + $ offset ; $ length = $ synonym [ 'end_offset' ] - $ synonym [ 'start_offset' ] ; $ rewrittenQueryText = $ this -> mbSubstrReplace ( $ queryText , $ synonym [ 'token' ] , $ startOffset , $ length ) ; $ newOffset = mb_strlen ( $ rewrittenQueryText ) - mb_strlen ( $ queryText ) + $ offset ; $ combinations [ $ rewrittenQueryText ] = $ substitutions + 1 ; if ( ! empty ( $ remainingSynonyms ) ) { $ combinations = array_merge ( $ combinations , $ this -> combineSynonyms ( $ rewrittenQueryText , $ remainingSynonyms , $ maxRewrites , $ substitutions + 1 , $ newOffset ) ) ; } } if ( ! empty ( $ remainingSynonyms ) ) { $ combinations = array_merge ( $ combinations , $ this -> combineSynonyms ( $ queryText , $ remainingSynonyms , $ maxRewrites , $ substitutions , $ offset ) ) ; } } return $ combinations ; }
Combine analysis result to provides all possible synonyms substitution comination.

@param string  $queryText          Original query text
@param array   $synonymByPositions Synonyms array by positions.
@param integer $maxRewrites        Max number of allowed rewrites.
@param int     $substitutions      Number of substitutions in the current query.
@param int     $offset             Offset of previous substitutions.

@return array
Combine analysis result to provides all possible synonyms substitution comination .