Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
8 / 8
QueryBuilderTraits
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
8 / 8
 checkTitleSearchRequestLength
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
8 / 8
<?php
namespace CirrusSearch\Query;
use CirrusSearch\CirrusSearch;
use CirrusSearch\Search\SearchContext;
/**
 * Various utility functions that can be shared across cirrus query builders
 */
trait QueryBuilderTraits {
    /**
     * Short circuits query execution with zero results when
     * the search is longer than possible. Query builders may
     * short circuit themselves based on the return value.
     *
     * @param string $term Term being searched for
     * @param SearchContext $searchContext Context to short circuit
     * @return bool True when $term is an acceptable length.
     */
    public function checkTitleSearchRequestLength( $term, SearchContext $searchContext ) {
        $requestLength = mb_strlen( $term );
        if ( $requestLength > CirrusSearch::MAX_TITLE_SEARCH ) {
            $searchContext->setResultsPossible( false );
            $searchContext->addWarning(
                'cirrussearch-query-too-long',
                $requestLength,
                CirrusSearch::MAX_TITLE_SEARCH
            );
            return false;
        } else {
            return true;
        }
    }
}