src/Graviton/DocumentBundle/Service/SolrQuery.php
private function getSingleTerm($term)
    {
        // we don't modify numbers
        if (ctype_digit($term)) {
            return '"'.$term.'"';
        }

        // formatted number?
        $formatted = str_replace(
            [
                '-',
                '.'
            ],
            '',
            $term
        );
        if (ctype_digit($formatted)) {
            return '"'.$term.'"';
        }

        // everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard
        // thanks to https://stackoverflow.com/a/7684859/3762521
        $pattern = '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/';
        if (strlen($term) > 3 && preg_match($pattern, $term, $matches) === 1) {
            return '"'.$term.'"';
        }

        // is it a solr field query (like id:333)?
        if (preg_match($this->fieldQueryPattern, $term) === 1) {
            return $this->parseSolrFieldQuery($term);
        }

        // strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy
        if (strlen($term) >= $this->solrFuzzyBridge) {
            return $this->doAndNotPrefixSingleTerm($term, '~');
        }

        if (strlen($term) >= $this->solrWildcardBridge) {
            return $this->doAndNotPrefixSingleTerm($term, '*');
        }

        return $term;
    }
private function getSingleTerm($term)
    {
        // we don't modify numbers
        if (ctype_digit($term)) {
            return '"'.$term.'"';
        }

        // formatted number?
        $formatted = str_replace(
            [
                '-',
                '.'
            ],
            '',
            $term
        );
        if (ctype_digit($formatted)) {
            return '"'.$term.'"';
        }

        // everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard
        // thanks to https://stackoverflow.com/a/7684859/3762521
        $pattern = '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/';
        if (strlen($term) > 3 && preg_match($pattern, $term, $matches) === 1) {
            return '"'.$term.'"';
        }

        // is it a solr field query (like id:333)?
        if (preg_match($this->fieldQueryPattern, $term) === 1) {
            return $this->parseSolrFieldQuery($term);
        }

        // strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy
        if (strlen($term) >= $this->solrFuzzyBridge) {
            return $this->doAndNotPrefixSingleTerm($term, '~');
        }

        if (strlen($term) >= $this->solrWildcardBridge) {
            return $this->doAndNotPrefixSingleTerm($term, '*');
        }

        return $term;
    }
private function getSingleTerm ( $ term ) { // we don't modify numbers if ( ctype_digit ( $ term ) ) { return '"' . $ term . '"' ; } // formatted number? $ formatted = str_replace ( [ '-' , '.' ] , '' , $ term ) ; if ( ctype_digit ( $ formatted ) ) { return '"' . $ term . '"' ; } // everything that is only numbers *and* characters and at least 3 long, we don't fuzzy/wildcard // thanks to https://stackoverflow.com/a/7684859/3762521 $ pattern = '/^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+)$/' ; if ( strlen ( $ term ) > 3 && preg_match ( $ pattern , $ term , $ matches ) === 1 ) { return '"' . $ term . '"' ; } // is it a solr field query (like id:333)? if ( preg_match ( $ this -> fieldQueryPattern , $ term ) === 1 ) { return $ this -> parseSolrFieldQuery ( $ term ) ; } // strings shorter then 5 chars (like hans) we wildcard, all others we make fuzzy if ( strlen ( $ term ) >= $ this -> solrFuzzyBridge ) { return $ this -> doAndNotPrefixSingleTerm ( $ term , '~' ) ; } if ( strlen ( $ term ) >= $ this -> solrWildcardBridge ) { return $ this -> doAndNotPrefixSingleTerm ( $ term , '*' ) ; } return $ term ; }
returns a single term how to search. here we can apply custom logic to the user input string

@param string $term single search term

@return string modified search term
returns a single term how to search . here we can apply custom logic to the user input string