PHP Trait Devise\Search\SearchableModelTrait

where numbers 1 and 2 are the respective relevance of those columns
Show file Open project: devisephp/cms

Protected Properties

Property Type Description
$totalWords integer

Public Methods

Method Description
scopeSearch ( $query, $search ) : mixed Makes the search process work for a model

Protected Methods

Method Description
addSelectsToQuery ( &$query, $selects ) Puts all the select clauses to the main query
createSearchQuery ( Query $query, text $search ) : Query Makes the search query to search for text by relevance inside the database using IF statements
filterCommonWords ( array $words ) : array Filter out words like a, the, but, and, her, his, etc <-- even that one
filterQueryWithRelevance ( &$query, $relevance_count ) Adds where clauses to this query based on the relevance
getColumns ( ) : array Returns the search columns
getJoins ( ) : array Returns the tables that has to join
getSearchQueriesForColumn ( string $column, integer $relevance, array $words ) : array Overrides how the relevance is calculated
makeJoins ( &$query ) Adds the join sql to the query

Method Details

addSelectsToQuery() protected method

Puts all the select clauses to the main query
protected addSelectsToQuery ( &$query, $selects )
$query
$selects

createSearchQuery() protected method

Makes the search query to search for text by relevance inside the database using IF statements
protected createSearchQuery ( Query $query, text $search ) : Query
$query Query
$search text
return Query

filterCommonWords() protected method

Filter out words like a, the, but, and, her, his, etc <-- even that one
protected filterCommonWords ( array $words ) : array
$words array
return array

filterQueryWithRelevance() protected method

Adds where clauses to this query based on the relevance
protected filterQueryWithRelevance ( &$query, $relevance_count )

getColumns() protected method

Returns the search columns
protected getColumns ( ) : array
return array

getJoins() protected method

Returns the tables that has to join
protected getJoins ( ) : array
return array

getSearchQueriesForColumn() protected method

Overrides how the relevance is calculated
protected getSearchQueriesForColumn ( string $column, integer $relevance, array $words ) : array
$column string
$relevance integer
$words array
return array

makeJoins() protected method

Adds the join sql to the query
protected makeJoins ( &$query )
$query

scopeSearch() public method

Makes the search process work for a model
public scopeSearch ( $query, $search ) : mixed
$query
$search
return mixed

Property Details

$totalWords protected property

protected int $totalWords
return integer