PHP Класс Sphinx\SphinxClient

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$anchor distributed retries delay
$arrayresult stored mbstring encoding
$connerror last warning message
$cutoff max matches to retrieve
$error select-list (attributes or expressions, with optional aliases)
$fieldweights max query time, milliseconds (default is 0, do not limit)
$filters max ID to match (default is 0, which means no limit)
$groupby search filters
$groupdistinct group-by sorting clause (to sort groups in result set with)
$groupfunc group-by attribute name
$groupsort group-by function (to pre-process group-by attribute value with)
$host
$indexweights geographical anchor point
$limit how many records to seek from result-set start (default is 0)
$maxid min ID to match (default is 0, which means no limit)
$maxmatches group-by count-distinct attribute
$maxquerytime ranking mode expression (for SPH_RANK_EXPR)
$mbenc requests array for multi-query
$minid attribute to sort by (default is "")
$mode how many records to return from result-set starting at offset (default is 20)
$offset socket connection
$overrides per-field-name weights
$path searchd port (default is 9312)
$port searchd host (default is "localhost")
$ranker per-index weights
$rankexpr ranking mode (default is SPH_RANK_PROXIMITY_BM25)
$reqs connection error vs remote error flag
$retrycount cutoff to stop searching at (default is 0)
$retrydelay distributed retries count
$select per-query attribute values overrides
$socket socket path
$sort per-field weights (default is 1 for all fields)
$sortby match sorting mode (default is SPH_SORT_RELEVANCE)
$timeout whether $result["matches"] should be a hash or an array
$warning last error message
$weights query matching mode (default is SPH_MATCH_ALL)

Открытые методы

Метод Описание
__construct ( ) Create a new client object and fill defaults
__destruct ( ) Close the socket upon exit
addQuery ( string $query, string $index = '*', string $comment = '' ) : integer Add a query to a multi-query batch. Returns index into results array from runQueries() call
buildExcerpts ( array $docs, string $index, string $words, array $opts = [] ) : array | false Connect to searchd and generate excerpts (snippets) from given documents for a given query
buildKeywords ( string $query, string $index, boolean $hits ) : array | false Extracts keywords from query using tokenizer settings for a given index
close ( ) : boolean Close a persistent connection
create ( ) : SphinxClient Creates a SphinxClient object. Chainable
escapeString ( string $string ) : string Escapes characters that are treated as special operators by the query language parser
fixUint ( integer $value ) : integer Fix broken unsigned int
flushAttributes ( ) : integer Forces searchd to flush pending attribute updates to disk, and blocks until completion
getLastError ( ) : string Get last error message
getLastWarning ( ) : string Get last warning message
isConnectError ( ) : boolean Get last error flag, to tell network connection errors from searchd errors or broken responses
open ( ) : boolean Open a persistent connection
packI64 ( integer | string $v ) : string Pack 64-bit signed
packU64 ( integer | string $v ) : string Pack 64-bit unsigned
query ( string $query, string $index = '*', string $comment = '' ) : array | false Connect to searchd server, run given search query through given indexes, and return the results
resetFilters ( ) : SphinxClient Clear all filters (for multi-queries)
resetGroupBy ( ) : SphinxClient Clear groupby settings (for multi-queries)
resetOverrides ( ) : SphinxClient Clear all attribute value overrides (for multi-queries)
runQueries ( ) : array Connect to searchd, run batch queries, and return an array of results
setArrayResult ( boolean $arrayresult ) : SphinxClient Set resultset format to either hash or array; hash is the default format
setConnectTimeout ( integer $timeout ) : SphinxClient Set server connection timeout
setFieldWeights ( array $weights ) : SphinxClient Bind per-field weights by name
setFilter ( string $attribute, array $values, boolean $exclude = false ) : SphinxClient Set values filter; only match records where $attribute value is in (or not in) the given set
setFilterFloatRange ( string $attribute, float $min, float $max, boolean $exclude = false ) : SphinxClient Set float range filter; only match records if $attribute value between $min and $max (inclusive)
setFilterRange ( string $attribute, integer $min, integer $max, boolean $exclude = false ) : SphinxClient Set range filter; only match records if $attribute value between $min and $max (inclusive)
setGeoAnchor ( string $attrlat, string $attrlong, float $lat, float $long ) : SphinxClient Set up anchor point for geosphere distance calculations. Required to use @geodist in filters and sorting
setGroupBy ( string $attribute, integer $func, string $groupsort = '@group desc' ) : SphinxClient Set grouping attribute and function
setGroupDistinct ( string $attribute ) : SphinxClient Set count-distinct attribute for group-by queries
setIdRange ( integer $min, integer $max ) : SphinxClient Limit the ID range; only match records if document ID is between $min and $max (inclusive)
setIndexWeights ( array $weights ) : SphinxClient Bind per-index weights by name
setLimits ( integer $offset, integer $limit, integer $max, integer $cutoff ) : SphinxClient Set offset and count into result set, optionally set max-matches and cutoff limits
setMatchMode ( integer $mode ) : SphinxClient Set matching mode
setMaxQueryTime ( integer $max ) : SphinxClient Set maximum query time, in milliseconds, per-index. 0 means "do not limit"
setOverride ( string $attrname, integer $attrtype, array $values ) : SphinxClient Set attribute values override. Only one override per attribute
setRankingMode ( integer $ranker, string $rankexpr = '' ) : SphinxClient Set ranking mode
setRetries ( integer $count, integer $delay ) : SphinxClient Set distributed retries count and delay
setSelect ( string $select ) : SphinxClient Set select-list (attributes or expressions), SQL-like syntax
setServer ( string $host, integer $port ) : SphinxClient Set searchd host name and port
setSortMode ( integer $mode, string $sortby = '' ) : SphinxClient Set matches sorting mode
setWeights ( array $weights ) : SphinxClient Bind per-field weights by order
status ( ) : array | false Queries searchd status
unpackI64 ( string $v ) : integer | string Unpack 64-bit signed
unpackU64 ( string $v ) : integer | string Unpack 64-bit unsigned
updateAttributes ( string $index, array $attrs, array $values, boolean $mva = false ) : integer Batch update given attributes in given documents

Приватные методы

Метод Описание
connect ( ) : resource | false Connect to searchd server
getResponse ( resource $fp, string $clientVer ) : string | false Get and check response packet from searchd server
mbPop ( ) Leave mbstring workaround mode
mbPush ( ) Enter mbstring workaround mode, when function overloading is enabled
packFloat ( float $float ) : string Helper to pack floats in network byte order
parseSearchResponse ( string $response, integer $nreqs ) : array Parse and return search query (or queries) response
send ( resource $handle, string $data, integer $length ) : boolean Write message to socket

Описание методов

__construct() публичный Метод

Create a new client object and fill defaults
public __construct ( )

__destruct() публичный Метод

Close the socket upon exit
public __destruct ( )

addQuery() публичный Метод

Add a query to a multi-query batch. Returns index into results array from runQueries() call
public addQuery ( string $query, string $index = '*', string $comment = '' ) : integer
$query string
$index string
$comment string
Результат integer Results array index.

buildExcerpts() публичный Метод

Connect to searchd and generate excerpts (snippets) from given documents for a given query
public buildExcerpts ( array $docs, string $index, string $words, array $opts = [] ) : array | false
$docs array array of strings that carry the document contents
$index string name of the index
$words string string that contains the keywords to highlight
$opts array hash which contains additional optional highlighting parameters
Результат array | false Array of snippets, or false on failure.

buildKeywords() публичный Метод

Extracts keywords from query using tokenizer settings for a given index
public buildKeywords ( string $query, string $index, boolean $hits ) : array | false
$query string query to extract keywords from
$index string name of the index to get tokenizing settings and keyword occurrence statistics from
$hits boolean whether keyword occurrence statistics are required
Результат array | false Array of hashes with per-keyword information, or false on failure.

close() публичный Метод

Close a persistent connection
public close ( ) : boolean
Результат boolean

create() публичный статический Метод

Creates a SphinxClient object. Chainable
public static create ( ) : SphinxClient
Результат SphinxClient

escapeString() публичный Метод

Escapes characters that are treated as special operators by the query language parser
public escapeString ( string $string ) : string
$string string unescaped string
Результат string Escaped string.

fixUint() публичный Метод

Fix broken unsigned int
public fixUint ( integer $value ) : integer
$value integer
Результат integer

flushAttributes() публичный Метод

Forces searchd to flush pending attribute updates to disk, and blocks until completion
public flushAttributes ( ) : integer
Результат integer Flush tag, -1 on error.

getLastError() публичный Метод

Get last error message
public getLastError ( ) : string
Результат string

getLastWarning() публичный Метод

Get last warning message
public getLastWarning ( ) : string
Результат string

isConnectError() публичный Метод

Get last error flag, to tell network connection errors from searchd errors or broken responses
public isConnectError ( ) : boolean
Результат boolean

open() публичный Метод

Open a persistent connection
public open ( ) : boolean
Результат boolean

packI64() публичный Метод

Pack 64-bit signed
public packI64 ( integer | string $v ) : string
$v integer | string
Результат string

packU64() публичный Метод

Pack 64-bit unsigned
public packU64 ( integer | string $v ) : string
$v integer | string
Результат string

query() публичный Метод

Connect to searchd server, run given search query through given indexes, and return the results
public query ( string $query, string $index = '*', string $comment = '' ) : array | false
$query string query string
$index string index name
$comment string optional comment
Результат array | false Results array, or false upon error.

resetFilters() публичный Метод

Clear all filters (for multi-queries)
public resetFilters ( ) : SphinxClient
Результат SphinxClient

resetGroupBy() публичный Метод

Clear groupby settings (for multi-queries)
public resetGroupBy ( ) : SphinxClient
Результат SphinxClient

resetOverrides() публичный Метод

Clear all attribute value overrides (for multi-queries)
public resetOverrides ( ) : SphinxClient
Результат SphinxClient

runQueries() публичный Метод

Connect to searchd, run batch queries, and return an array of results
public runQueries ( ) : array
Результат array Result array.

setArrayResult() публичный Метод

PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs
public setArrayResult ( boolean $arrayresult ) : SphinxClient
$arrayresult boolean whether to return results as array keyed by ID
Результат SphinxClient

setConnectTimeout() публичный Метод

Set server connection timeout
public setConnectTimeout ( integer $timeout ) : SphinxClient
$timeout integer
Результат SphinxClient

setFieldWeights() публичный Метод

Bind per-field weights by name
public setFieldWeights ( array $weights ) : SphinxClient
$weights array
Результат SphinxClient

setFilter() публичный Метод

Set values filter; only match records where $attribute value is in (or not in) the given set
public setFilter ( string $attribute, array $values, boolean $exclude = false ) : SphinxClient
$attribute string attribute name
$values array value set
$exclude boolean whether the filter is exclusive or inclusive
Результат SphinxClient

setFilterFloatRange() публичный Метод

Set float range filter; only match records if $attribute value between $min and $max (inclusive)
public setFilterFloatRange ( string $attribute, float $min, float $max, boolean $exclude = false ) : SphinxClient
$attribute string attribute name
$min float minimum attribute value
$max float maximum attribute value
$exclude boolean whether the filter is exclusive or inclusive
Результат SphinxClient

setFilterRange() публичный Метод

Set range filter; only match records if $attribute value between $min and $max (inclusive)
public setFilterRange ( string $attribute, integer $min, integer $max, boolean $exclude = false ) : SphinxClient
$attribute string attribute name
$min integer minimum attribute value
$max integer maximum attribute value
$exclude boolean whether the filter is exclusive or inclusive
Результат SphinxClient

setGeoAnchor() публичный Метод

Set up anchor point for geosphere distance calculations. Required to use @geodist in filters and sorting
public setGeoAnchor ( string $attrlat, string $attrlong, float $lat, float $long ) : SphinxClient
$attrlat string latitude attribute name
$attrlong string longitude attribute name
$lat float anchor point latitude (in radians)
$long float anchor point longitude (in radians)
Результат SphinxClient

setGroupBy() публичный Метод

Set grouping attribute and function
public setGroupBy ( string $attribute, integer $func, string $groupsort = '@group desc' ) : SphinxClient
$attribute string attribute name
$func integer grouping function
$groupsort string group sorting clause
Результат SphinxClient

setGroupDistinct() публичный Метод

Set count-distinct attribute for group-by queries
public setGroupDistinct ( string $attribute ) : SphinxClient
$attribute string attribute name
Результат SphinxClient

setIdRange() публичный Метод

Limit the ID range; only match records if document ID is between $min and $max (inclusive)
public setIdRange ( integer $min, integer $max ) : SphinxClient
$min integer minimum document ID
$max integer maximum document ID
Результат SphinxClient

setIndexWeights() публичный Метод

Bind per-index weights by name
public setIndexWeights ( array $weights ) : SphinxClient
$weights array
Результат SphinxClient

setLimits() публичный Метод

Set offset and count into result set, optionally set max-matches and cutoff limits
public setLimits ( integer $offset, integer $limit, integer $max, integer $cutoff ) : SphinxClient
$offset integer
$limit integer
$max integer
$cutoff integer
Результат SphinxClient

setMatchMode() публичный Метод

Set matching mode
public setMatchMode ( integer $mode ) : SphinxClient
$mode integer
Результат SphinxClient

setMaxQueryTime() публичный Метод

Set maximum query time, in milliseconds, per-index. 0 means "do not limit"
public setMaxQueryTime ( integer $max ) : SphinxClient
$max integer
Результат SphinxClient

setOverride() публичный Метод

Set attribute values override. Only one override per attribute
public setOverride ( string $attrname, integer $attrtype, array $values ) : SphinxClient
$attrname string attribute name
$attrtype integer attribute type
$values array hash that maps document IDs to attribute values
Результат SphinxClient

setRankingMode() публичный Метод

Set ranking mode
public setRankingMode ( integer $ranker, string $rankexpr = '' ) : SphinxClient
$ranker integer
$rankexpr string
Результат SphinxClient

setRetries() публичный Метод

Set distributed retries count and delay
public setRetries ( integer $count, integer $delay ) : SphinxClient
$count integer
$delay integer
Результат SphinxClient

setSelect() публичный Метод

Set select-list (attributes or expressions), SQL-like syntax
public setSelect ( string $select ) : SphinxClient
$select string select list
Результат SphinxClient

setServer() публичный Метод

Set searchd host name and port
public setServer ( string $host, integer $port ) : SphinxClient
$host string
$port integer
Результат SphinxClient

setSortMode() публичный Метод

Set matches sorting mode
public setSortMode ( integer $mode, string $sortby = '' ) : SphinxClient
$mode integer
$sortby string
Результат SphinxClient

setWeights() публичный Метод

DEPRECATED; use SetFieldWeights() instead
public setWeights ( array $weights ) : SphinxClient
$weights array
Результат SphinxClient

status() публичный Метод

Queries searchd status
public status ( ) : array | false
Результат array | false Status variable name and value pairs, false on error.

unpackI64() публичный Метод

Unpack 64-bit signed
public unpackI64 ( string $v ) : integer | string
$v string
Результат integer | string

unpackU64() публичный Метод

Unpack 64-bit unsigned
public unpackU64 ( string $v ) : integer | string
$v string
Результат integer | string

updateAttributes() публичный Метод

Batch update given attributes in given documents
public updateAttributes ( string $index, array $attrs, array $values, boolean $mva = false ) : integer
$index string search index
$attrs array array of attribute names
$values array hash of arrays of new attribute values keyed by document ID
$mva boolean whether to treat attributes as MVAs
Результат integer Amount of updated documents (0 or more) on success, -1 on failure

Описание свойств

$anchor публичное свойство

distributed retries delay
public $anchor

$arrayresult публичное свойство

stored mbstring encoding
public $arrayresult

$connerror публичное свойство

last warning message
public $connerror

$cutoff публичное свойство

max matches to retrieve
public $cutoff

$error публичное свойство

select-list (attributes or expressions, with optional aliases)
public $error

$fieldweights публичное свойство

max query time, milliseconds (default is 0, do not limit)
public $fieldweights

$filters публичное свойство

max ID to match (default is 0, which means no limit)
public $filters

$groupby публичное свойство

search filters
public $groupby

$groupdistinct публичное свойство

group-by sorting clause (to sort groups in result set with)
public $groupdistinct

$groupfunc публичное свойство

group-by attribute name
public $groupfunc

$groupsort публичное свойство

group-by function (to pre-process group-by attribute value with)
public $groupsort

$host публичное свойство

public $host

$indexweights публичное свойство

geographical anchor point
public $indexweights

$limit публичное свойство

how many records to seek from result-set start (default is 0)
public $limit

$maxid публичное свойство

min ID to match (default is 0, which means no limit)
public $maxid

$maxmatches публичное свойство

group-by count-distinct attribute
public $maxmatches

$maxquerytime публичное свойство

ranking mode expression (for SPH_RANK_EXPR)
public $maxquerytime

$mbenc публичное свойство

requests array for multi-query
public $mbenc

$minid публичное свойство

attribute to sort by (default is "")
public $minid

$mode публичное свойство

how many records to return from result-set starting at offset (default is 20)
public $mode

$offset публичное свойство

socket connection
public $offset

$overrides публичное свойство

per-field-name weights
public $overrides

$path публичное свойство

searchd port (default is 9312)
public $path

$port публичное свойство

searchd host (default is "localhost")
public $port

$ranker публичное свойство

per-index weights
public $ranker

$rankexpr публичное свойство

ranking mode (default is SPH_RANK_PROXIMITY_BM25)
public $rankexpr

$reqs публичное свойство

connection error vs remote error flag
public $reqs

$retrycount публичное свойство

cutoff to stop searching at (default is 0)
public $retrycount

$retrydelay публичное свойство

distributed retries count
public $retrydelay

$select публичное свойство

per-query attribute values overrides
public $select

$socket публичное свойство

socket path
public $socket

$sort публичное свойство

per-field weights (default is 1 for all fields)
public $sort

$sortby публичное свойство

match sorting mode (default is SPH_SORT_RELEVANCE)
public $sortby

$timeout публичное свойство

whether $result["matches"] should be a hash or an array
public $timeout

$warning публичное свойство

last error message
public $warning

$weights публичное свойство

query matching mode (default is SPH_MATCH_ALL)
public $weights