Search
in package
Functions for front-end search indexing
Table of Contents
Constants
- WORD_LENGTH : mixed = 16
Properties
- $stop_words : mixed
- $query_and : mixed
- $record_id : mixed
- $table : mixed
Methods
- cleanup() : mixed
- Looks for syncronisation errors in the indexes and fixes them
- clearIndex() : mixed
- Clears the index chosen with selectIndex()
- filterStopWords() : array<string|int, mixed>
- Remove "stop words" from keyword list
- indexHtml() : mixed
- Splits up html, and adds the keywords which are found into the index chosen with selectIndex() Usually should be run from within a transaction
- indexText() : mixed
- Splits up text, and adds the keywords which are found into the index chosen with selectIndex() Usually should be run from within a transaction
- paginate() : mixed
- Return HTML to perform pagination.
- query() : array<string|int, mixed>|false
- Does a query for a term, against a set of search handlers
- queryAnd() : mixed
- Set the 'query_and' parameter, which defines the handling of search terms
- selectIndex() : void
- Selects the currently active index
- addWordsIndex() : mixed
- Accepts an array of relevant words and adds it into the index chosen with selectIndex() Usually should be run from within a transaction
Constants
WORD_LENGTH
public
mixed
WORD_LENGTH
= 16
Properties
$stop_words
public
static mixed
$stop_words
= array('a', 'above', 'across', 'after', 'afterwards', 'again', 'against', 'all', 'almost', 'alone', 'along', 'already', 'also', 'although', 'always', 'am', 'among', 'amongst', 'amoungst', 'amount', 'an', 'and', 'another', 'any', 'anyhow', 'anyone', 'anything', 'anyway', 'anywhere', 'are', 'around', 'as', 'at', 'b', 'back', 'be', 'became', 'because', 'become', 'becomes', 'becoming', 'been', 'before', 'beforehand', 'behind', 'being', 'below', 'beside', 'besides', 'between', 'beyond', 'bill', 'both', 'bottom', 'but', 'by', 'c', 'call', 'can', 'cannot', 'cant', 'co', 'con', 'could', 'couldnt', 'cry', 'd', 'de', 'describe', 'detail', 'do', 'done', 'down', 'due', 'during', 'each', 'e', 'eg', 'eight', 'either', 'eleven', 'else', 'elsewhere', 'empty', 'enough', 'etc', 'even', 'ever', 'every', 'everyone', 'everything', 'everywhere', 'except', 'f', 'few', 'fifteen', 'fill', 'find', 'fire', 'first', 'five', 'for', 'former', 'formerly', 'forty', 'found', 'four', 'from', 'front', 'full', 'further', 'g', 'get', 'give', 'go', 'h', 'had', 'has', 'hasnt', 'have', 'he', 'hence', 'her', 'here', 'hereafter', 'hereby', 'herein', 'hereupon', 'hers', 'herself', 'him', 'himself', 'his', 'how', 'however', 'hundred', 'i', 'ie', 'if', 'in', 'inc', 'indeed', 'interest', 'into', 'is', 'it', 'its', 'itself', 'j', 'k', 'keep', 'l', 'last', 'latter', 'latterly', 'least', 'less', 'ltd', 'm', 'made', 'many', 'may', 'me', 'meanwhile', 'might', 'mill', 'mine', 'more', 'moreover', 'most', 'mostly', 'move', 'much', 'must', 'my', 'myself', 'n', 'name', 'namely', 'neither', 'never', 'nevertheless', 'next', 'nine', 'no', 'nobody', 'none', 'noone', 'nor', 'not', 'nothing', 'now', 'nowhere', 'o', 'of', 'off', 'often', 'on', 'once', 'one', 'only', 'onto', 'or', 'other', 'others', 'otherwise', 'our', 'ours', 'ourselves', 'out', 'over', 'own', 'p', 'part', 'per', 'perhaps', 'please', 'put', 'q', 'r', 'rather', 're', 's', 'same', 'see', 'seem', 'seemed', 'seeming', 'seems', 'serious', 'several', 'she', 'should', 'show', 'side', 'since', 'sincere', 'six', 'sixty', 'so', 'some', 'somehow', 'someone', 'something', 'sometime', 'sometimes', 'somewhere', 'still', 'such', 'system', 't', 'take', 'ten', 'than', 'that', 'the', 'their', 'them', 'themselves', 'then', 'thence', 'there', 'thereafter', 'thereby', 'therefore', 'therein', 'thereupon', 'these', 'they', 'thick', 'thin', 'third', 'this', 'those', 'though', 'three', 'through', 'throughout', 'thus', 'to', 'together', 'too', 'top', 'toward', 'towards', 'twelve', 'twenty', 'two', 'u', 'un', 'under', 'until', 'up', 'upon', 'us', 'v', 'very', 'via', 'w', 'was', 'we', 'well', 'were', 'what', 'whatever', 'when', 'whence', 'whenever', 'where', 'whereafter', 'whereas', 'whereby', 'wherein', 'whereupon', 'wherever', 'whether', 'which', 'while', 'whither', 'who', 'whoever', 'whole', 'whom', 'whose', 'why', 'will', 'with', 'within', 'without', 'would', 'x', 'y', 'yet', 'you', 'your', 'yours', 'yourself', 'yourselves', 'z')
$query_and
private
static mixed
$query_and
= false
$record_id
private
static mixed
$record_id
$table
private
static mixed
$table
Methods
cleanup()
Looks for syncronisation errors in the indexes and fixes them
public
static cleanup(mixed $reference_table) : mixed
Parameters
- $reference_table : mixed
clearIndex()
Clears the index chosen with selectIndex()
public
static clearIndex() : mixed
filterStopWords()
Remove "stop words" from keyword list
public
static filterStopWords(array<string|int, mixed> $keywords) : array<string|int, mixed>
Parameters
- $keywords : array<string|int, mixed>
Return values
array<string|int, mixed> —With removed stop words
indexHtml()
Splits up html, and adds the keywords which are found into the index chosen with selectIndex() Usually should be run from within a transaction
public
static indexHtml(string $text[, float $relevancy_multiplier = 1 ]) : mixed
Parameters
- $text : string
-
The text to process.
- $relevancy_multiplier : float = 1
-
A multiplier to apply to the relavancy of all keywords found.
indexText()
Splits up text, and adds the keywords which are found into the index chosen with selectIndex() Usually should be run from within a transaction
public
static indexText(string $text[, float $relevancy_multiplier = 1 ]) : mixed
Parameters
- $text : string
-
The text to process.
- $relevancy_multiplier : float = 1
-
A multiplier to apply to the relavancy of all keywords found.
paginate()
Return HTML to perform pagination.
public
static paginate(mixed $curr_page, mixed $num_pages[, mixed $div_class = null ]) : mixed
$curr_page The current page number (1-based). $num_page The total number of pages. $div_class If provided, a wrapper div will be generated, with this class name.
Parameters
- $curr_page : mixed
- $num_pages : mixed
- $div_class : mixed = null
query()
Does a query for a term, against a set of search handlers
public
static query(string|array<string|int, mixed> $query, array<string|int, mixed> $search_handlers[, int $page = 0 ][, int $num_per_page = null ]) : array<string|int, mixed>|false
Parameters
- $query : string|array<string|int, mixed>
-
The keyword(s) to search for.
- $search_handlers : array<string|int, mixed>
-
Search handlers to use. Expects an array of SearchHandler objects.
- $page : int = 0
-
The page number to show. Should be 0-based (first page is num 0)
- $num_per_page : int = null
-
The number of records to show per page. Defaults to a the sprout config option
Return values
array<string|int, mixed>|false —The array contains 4 keys: [0] PDOStatement, with three columns: record_id; controller_class; relevancy. [1] array The list of keywords used for the search [2] int The total number of results available; results are paginated, so this is likely to be more than the number of results returned. [3] int The total number of pages of results Returns false if no queries were generated
queryAnd()
Set the 'query_and' parameter, which defines the handling of search terms
public
static queryAnd(mixed $val) : mixed
Parameters
- $val : mixed
selectIndex()
Selects the currently active index
public
static selectIndex(string $table, int $record_id) : void
Parameters
- $table : string
-
Table name, without prefix
- $record_id : int
-
Record ID
addWordsIndex()
Accepts an array of relevant words and adds it into the index chosen with selectIndex() Usually should be run from within a transaction
private
static addWordsIndex(array<string|int, mixed> $words[, float $relevancy_multiplier = 1 ]) : mixed
Parameters
- $words : array<string|int, mixed>
-
word => relevancy mapping
- $relevancy_multiplier : float = 1