src/Graviton/DocumentBundle/Service/SolrQuery.php
private function getSearchTerm(SearchNode $node)
    {
        $fullTerm = $node->getSearchQuery();

        foreach ($this->fullTermPatterns as $pattern) {
            if (preg_match($pattern, $fullTerm, $matches) === 1) {
                return '"'.$fullTerm.'"';
            }
        }

        if ($this->andifyTerms) {
            $glue = 'AND';
        } else {
            $glue = '';
        }


        $i = 0;
        $hasPreviousOperator = false;
        $fullSearchElements = [];

        foreach (explode(' ', $node->getSearchQuery()) as $term) {
            $i++;

            // is this an operator?
            if (array_search($term, $this->queryOperators) !== false) {
                $fullSearchElements[] = $term;
                $hasPreviousOperator = true;
                continue;
            }

            $singleTerm = $this->getSingleTerm($term);

            if ($i > 1 && $hasPreviousOperator == false && !empty($glue)) {
                $fullSearchElements[] = $glue;
            } else {
                $hasPreviousOperator = false;
            }

            $fullSearchElements[] = $singleTerm;
        }

        return implode(' ', $fullSearchElements);
    }
private function getSearchTerm(SearchNode $node)
    {
        $fullTerm = $node->getSearchQuery();

        foreach ($this->fullTermPatterns as $pattern) {
            if (preg_match($pattern, $fullTerm, $matches) === 1) {
                return '"'.$fullTerm.'"';
            }
        }

        if ($this->andifyTerms) {
            $glue = 'AND';
        } else {
            $glue = '';
        }


        $i = 0;
        $hasPreviousOperator = false;
        $fullSearchElements = [];

        foreach (explode(' ', $node->getSearchQuery()) as $term) {
            $i++;

            // is this an operator?
            if (array_search($term, $this->queryOperators) !== false) {
                $fullSearchElements[] = $term;
                $hasPreviousOperator = true;
                continue;
            }

            $singleTerm = $this->getSingleTerm($term);

            if ($i > 1 && $hasPreviousOperator == false && !empty($glue)) {
                $fullSearchElements[] = $glue;
            } else {
                $hasPreviousOperator = false;
            }

            $fullSearchElements[] = $singleTerm;
        }

        return implode(' ', $fullSearchElements);
    }
private function getSearchTerm ( SearchNode $ node ) { $ fullTerm = $ node -> getSearchQuery ( ) ; foreach ( $ this -> fullTermPatterns as $ pattern ) { if ( preg_match ( $ pattern , $ fullTerm , $ matches ) === 1 ) { return '"' . $ fullTerm . '"' ; } } if ( $ this -> andifyTerms ) { $ glue = 'AND' ; } else { $ glue = '' ; } $ i = 0 ; $ hasPreviousOperator = false ; $ fullSearchElements = [ ] ; foreach ( explode ( ' ' , $ node -> getSearchQuery ( ) ) as $ term ) { $ i ++ ; // is this an operator? if ( array_search ( $ term , $ this -> queryOperators ) !== false ) { $ fullSearchElements [ ] = $ term ; $ hasPreviousOperator = true ; continue ; } $ singleTerm = $ this -> getSingleTerm ( $ term ) ; if ( $ i > 1 && $ hasPreviousOperator == false && ! empty ( $ glue ) ) { $ fullSearchElements [ ] = $ glue ; } else { $ hasPreviousOperator = false ; } $ fullSearchElements [ ] = $ singleTerm ; } return implode ( ' ' , $ fullSearchElements ) ; }
returns the string search term to be used in the solr query

@param SearchNode $node the search node

@return string the composed search query
returns the string search term to be used in the solr query