PHP Class Bolt\Storage\Query\SearchWeighter

Show file Open project: bolt/bolt

Protected Properties

Property Type Description
$config SearchConfig
$contentType string
$results QueryResultset | array
$searchWords array

Public Methods

Method Description
__construct ( SearchConfig $config ) Constructor takes a compiled SearchConfig which is essentially an array of fields that we will search for text content, along with their corresponding weighting score.
setContentType ( string $type ) Sets the ContentType that we are weighting, that is, what type the results array is. That allows us to map against the configuration to see which fields to scan for relevant text.
setResults ( array $results ) Sets an iterable group of results, this normally comes directly from the database query.
setSearchWords ( array $words ) Sets the words that we want to query against. Normally this comes from the filter in a search, exploded into an array so the words are separated.
weight ( ) : array This is the public method that gets a score for a the set of results.

Protected Methods

Method Description
buildResultIndex ( Object $result ) : array This is a simple version of the Vector Space Model.
getContentFields ( ) : array | false Helper method to fetch the fields for an individual ContentType.
getResultScore ( Object $result ) : float This method uses the index built in the method above to do some quick score calculations for each word of the query, versus each word of the index dictionary.

Method Details

__construct() public method

Constructor takes a compiled SearchConfig which is essentially an array of fields that we will search for text content, along with their corresponding weighting score.
public __construct ( SearchConfig $config )
$config SearchConfig

getContentFields() protected method

Helper method to fetch the fields for an individual ContentType.
protected getContentFields ( ) : array | false
return array | false

getResultScore() protected method

This method uses the index built in the method above to do some quick score calculations for each word of the query, versus each word of the index dictionary.
protected getResultScore ( Object $result ) : float
$result Object
return float

setContentType() public method

Sets the ContentType that we are weighting, that is, what type the results array is. That allows us to map against the configuration to see which fields to scan for relevant text.
public setContentType ( string $type )
$type string

setResults() public method

Sets an iterable group of results, this normally comes directly from the database query.
public setResults ( array $results )
$results array

setSearchWords() public method

Sets the words that we want to query against. Normally this comes from the filter in a search, exploded into an array so the words are separated.
public setSearchWords ( array $words )
$words array

weight() public method

This is the public method that gets a score for a the set of results.
public weight ( ) : array
return array An array of scores for each of the corresponding results

Property Details

$config protected property

protected SearchConfig,Bolt\Storage\Query $config
return SearchConfig

$contentType protected property

protected string $contentType
return string

$results protected property

protected QueryResultset,Bolt\Storage\Query|array $results
return QueryResultset | array

$searchWords protected property

protected array $searchWords
return array