Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| QueryBuilderTraits | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| checkTitleSearchRequestLength | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CirrusSearch\Query; |
| 4 | |
| 5 | use CirrusSearch\CirrusSearch; |
| 6 | use CirrusSearch\Search\SearchContext; |
| 7 | |
| 8 | /** |
| 9 | * Various utility functions that can be shared across cirrus query builders |
| 10 | */ |
| 11 | trait 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 | } |