Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
QueryBuilderTraits
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 checkTitleSearchRequestLength
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace CirrusSearch\Query;
4
5use CirrusSearch\CirrusSearch;
6use CirrusSearch\Search\SearchContext;
7
8/**
9 * Various utility functions that can be shared across cirrus query builders
10 */
11trait QueryBuilderTraits {
12    /**
13     * Short circuits query execution with zero results when
14     * the search is longer than possible. Query builders may
15     * short circuit themselves based on the return value.
16     *
17     * @param string $term Term being searched for
18     * @param SearchContext $searchContext Context to short circuit
19     * @return bool True when $term is an acceptable length.
20     */
21    public function checkTitleSearchRequestLength( $term, SearchContext $searchContext ) {
22        $requestLength = mb_strlen( $term );
23        if ( $requestLength > CirrusSearch::MAX_TITLE_SEARCH ) {
24            $searchContext->setResultsPossible( false );
25            $searchContext->addWarning(
26                'cirrussearch-query-too-long',
27                $requestLength,
28                CirrusSearch::MAX_TITLE_SEARCH
29            );
30            return false;
31        } else {
32            return true;
33        }
34    }
35}