PHP Class SphinxClient

Author: Andrew Aksyonoff ([email protected])
ファイルを表示 Open project: xiuno/xiunobbs Class Usage Examples

Public Properties

Property Type Description
$_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)
$_max_id < 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
$_min_id < attribute to sort by (defualt is "")
$_mode < how many records to return from result-set starting at offset (default is 20)
$_offset < searchd port (default is 9312)
$_overrides < per-field-name weights
$_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
$_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)

Public Methods

Method Description
AddQuery ( $query, $index = "*", $comment = "" ) returns index into results array from RunQueries() call
BuildExcerpts ( $docs, $index, $words, $opts = [] ) an array of snippets on success
BuildKeywords ( $query, $index, $hits ) an array of words on success
Close ( )
EscapeString ( $string )
FlushAttributes ( )
GetLastError ( ) get last error message (string)
GetLastWarning ( ) get last warning message (string)
IsConnectError ( ) get last error flag (to tell network connection errors from searchd errors or broken responses)
Open ( )
Query ( $query, $index = "*", $comment = "" ) and return the search results
ResetFilters ( ) clear all filters (for multi-queries)
ResetGroupBy ( ) clear groupby settings (for multi-queries)
ResetOverrides ( ) clear all attribute value overrides (for multi-queries)
RunQueries ( ) connect to searchd, run queries batch, and return an array of result sets
SetArrayResult ( $arrayresult ) PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs
SetConnectTimeout ( $timeout ) set server connection timeout (0 to remove)
SetFieldWeights ( $weights ) bind per-field weights by name
SetFilter ( $attribute, $values, $exclude = false ) only match records where $attribute value is in given set
SetFilterFloatRange ( $attribute, $min, $max, $exclude = false ) only match records if $attribute value is beetwen $min and $max (inclusive)
SetFilterRange ( $attribute, $min, $max, $exclude = false ) only match records if $attribute value is beetwen $min and $max (inclusive)
SetGeoAnchor ( $attrlat, $attrlong, $lat, $long ) latitude and longitude must be in radians
SetGroupBy ( $attribute, $func, $groupsort = "@group desc" ) set grouping attribute and function
SetGroupDistinct ( $attribute ) set count-distinct attribute for group-by queries
SetIDRange ( $min, $max ) only match records if document ID is beetwen $min and $max (inclusive)
SetIndexWeights ( $weights ) bind per-index weights by name
SetLimits ( $offset, $limit, $max, $cutoff ) and optionally set max-matches and cutoff limits
SetMatchMode ( $mode ) set matching mode
SetMaxQueryTime ( $max ) integer, 0 means "do not limit"
SetOverride ( $attrname, $attrtype, $values ) $values must be a hash that maps document IDs to attribute values
SetRankingMode ( $ranker, $rankexpr = "" ) set ranking mode
SetRetries ( $count, $delay ) set distributed retries count and delay
SetSelect ( $select ) set select-list (attributes or expressions), SQL-like syntax
SetServer ( $host, $port ) set searchd host name (string) and port (integer)
SetSortMode ( $mode, $sortby = "" ) set matches sorting mode
SetWeights ( $weights ) DEPRECATED; use SetFieldWeights() instead
SphinxClient ( ) create a new client object and fill defaults
Status ( )
UpdateAttributes ( $index, $attrs, $values, $mva = false ) returns amount of updated documents (0 or more) on success, or -1 on failure
_Connect ( ) connect to searchd server
_GetResponse ( $fp, $client_ver ) get and check response packet from searchd server
_MBPop ( ) leave mbstring workaround mode
_MBPush ( ) enter mbstring workaround mode
_PackFloat ( $f ) helper to pack floats in network byte order
_ParseSearchResponse ( $response, $nreqs ) parse and return search query (or queries) response
_Send ( $handle, $data, $length )
__destruct ( )

Method Details

AddQuery() public method

returns index into results array from RunQueries() call
public AddQuery ( $query, $index = "*", $comment = "" )

BuildExcerpts() public method

an array of snippets on success
public BuildExcerpts ( $docs, $index, $words, $opts = [] )

BuildKeywords() public method

an array of words on success
public BuildKeywords ( $query, $index, $hits )

Close() public method

public Close ( )

EscapeString() public method

public EscapeString ( $string )

FlushAttributes() public method

public FlushAttributes ( )

GetLastError() public method

get last error message (string)
public GetLastError ( )

GetLastWarning() public method

get last warning message (string)
public GetLastWarning ( )

IsConnectError() public method

get last error flag (to tell network connection errors from searchd errors or broken responses)
public IsConnectError ( )

Open() public method

public Open ( )

Query() public method

and return the search results
public Query ( $query, $index = "*", $comment = "" )

ResetFilters() public method

clear all filters (for multi-queries)
public ResetFilters ( )

ResetGroupBy() public method

clear groupby settings (for multi-queries)
public ResetGroupBy ( )

ResetOverrides() public method

clear all attribute value overrides (for multi-queries)
public ResetOverrides ( )

RunQueries() public method

connect to searchd, run queries batch, and return an array of result sets
public RunQueries ( )

SetArrayResult() public method

PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs
public SetArrayResult ( $arrayresult )

SetConnectTimeout() public method

set server connection timeout (0 to remove)
public SetConnectTimeout ( $timeout )

SetFieldWeights() public method

bind per-field weights by name
public SetFieldWeights ( $weights )

SetFilter() public method

only match records where $attribute value is in given set
public SetFilter ( $attribute, $values, $exclude = false )

SetFilterFloatRange() public method

only match records if $attribute value is beetwen $min and $max (inclusive)
public SetFilterFloatRange ( $attribute, $min, $max, $exclude = false )

SetFilterRange() public method

only match records if $attribute value is beetwen $min and $max (inclusive)
public SetFilterRange ( $attribute, $min, $max, $exclude = false )

SetGeoAnchor() public method

latitude and longitude must be in radians
public SetGeoAnchor ( $attrlat, $attrlong, $lat, $long )

SetGroupBy() public method

set grouping attribute and function
public SetGroupBy ( $attribute, $func, $groupsort = "@group desc" )

SetGroupDistinct() public method

set count-distinct attribute for group-by queries
public SetGroupDistinct ( $attribute )

SetIDRange() public method

only match records if document ID is beetwen $min and $max (inclusive)
public SetIDRange ( $min, $max )

SetIndexWeights() public method

bind per-index weights by name
public SetIndexWeights ( $weights )

SetLimits() public method

and optionally set max-matches and cutoff limits
public SetLimits ( $offset, $limit, $max, $cutoff )

SetMatchMode() public method

set matching mode
public SetMatchMode ( $mode )

SetMaxQueryTime() public method

integer, 0 means "do not limit"
public SetMaxQueryTime ( $max )

SetOverride() public method

$values must be a hash that maps document IDs to attribute values
public SetOverride ( $attrname, $attrtype, $values )

SetRankingMode() public method

set ranking mode
public SetRankingMode ( $ranker, $rankexpr = "" )

SetRetries() public method

set distributed retries count and delay
public SetRetries ( $count, $delay )

SetSelect() public method

set select-list (attributes or expressions), SQL-like syntax
public SetSelect ( $select )

SetServer() public method

set searchd host name (string) and port (integer)
public SetServer ( $host, $port )

SetSortMode() public method

set matches sorting mode
public SetSortMode ( $mode, $sortby = "" )

SetWeights() public method

DEPRECATED; use SetFieldWeights() instead
public SetWeights ( $weights )

SphinxClient() public method

create a new client object and fill defaults
public SphinxClient ( )

Status() public method

public Status ( )

UpdateAttributes() public method

returns amount of updated documents (0 or more) on success, or -1 on failure
public UpdateAttributes ( $index, $attrs, $values, $mva = false )

_Connect() public method

connect to searchd server
public _Connect ( )

_GetResponse() public method

get and check response packet from searchd server
public _GetResponse ( $fp, $client_ver )

_MBPop() public method

leave mbstring workaround mode
public _MBPop ( )

_MBPush() public method

enter mbstring workaround mode
public _MBPush ( )

_PackFloat() public method

helper to pack floats in network byte order
public _PackFloat ( $f )

_ParseSearchResponse() public method

parse and return search query (or queries) response
public _ParseSearchResponse ( $response, $nreqs )

_Send() public method

public _Send ( $handle, $data, $length )

__destruct() public method

public __destruct ( )

Property Details

$_anchor public_oe property

< distributed retries delay
public $_anchor

$_arrayresult public_oe property

< stored mbstring encoding
public $_arrayresult

$_connerror public_oe property

< last warning message
public $_connerror

$_cutoff public_oe property

< max matches to retrieve
public $_cutoff

$_error public_oe property

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

$_fieldweights public_oe property

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

$_filters public_oe property

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

$_groupby public_oe property

< search filters
public $_groupby

$_groupdistinct public_oe property

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

$_groupfunc public_oe property

< group-by attribute name
public $_groupfunc

$_groupsort public_oe property

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

$_host public_oe property

public $_host

$_indexweights public_oe property

< geographical anchor point
public $_indexweights

$_limit public_oe property

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

$_max_id public_oe property

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

$_maxmatches public_oe property

< group-by count-distinct attribute
public $_maxmatches

$_maxquerytime public_oe property

< ranking mode expression (for SPH_RANK_EXPR)
public $_maxquerytime

$_mbenc public_oe property

< requests array for multi-query
public $_mbenc

$_min_id public_oe property

< attribute to sort by (defualt is "")
public $_min_id

$_mode public_oe property

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

$_offset public_oe property

< searchd port (default is 9312)
public $_offset

$_overrides public_oe property

< per-field-name weights
public $_overrides

$_port public_oe property

< searchd host (default is "localhost")
public $_port

$_ranker public_oe property

< per-index weights
public $_ranker

$_rankexpr public_oe property

< ranking mode (default is SPH_RANK_PROXIMITY_BM25)
public $_rankexpr

$_reqs public_oe property

< connection error vs remote error flag
public $_reqs

$_retrycount public_oe property

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

$_retrydelay public_oe property

< distributed retries count
public $_retrydelay

$_select public_oe property

< per-query attribute values overrides
public $_select

$_sort public_oe property

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

$_sortby public_oe property

< match sorting mode (default is SPH_SORT_RELEVANCE)
public $_sortby

$_timeout public_oe property

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

$_warning public_oe property

< last error message
public $_warning

$_weights public_oe property

< query matching mode (default is SPH_MATCH_ALL)
public $_weights