Documentation ¶
Index ¶
- Constants
- Variables
- func DegreeToRadian(degree float32) float32
- func EscapeString(s string) string
- type Client
- func (sc *Client) AddQuery(query, index, comment string) (i int, err error)
- func (sc *Client) BuildExcerpts(docs []string, index, words string, opts ExcerptsOpts) (resDocs []string, err error)
- func (sc *Client) BuildKeywords(query, index string, hits bool) (keywords []Keyword, err error)
- func (sc *Client) Close() error
- func (sc *Client) Error() error
- func (sc *Client) FlushAttributes() (iFlushTag int, err error)
- func (sc *Client) GetLastError() error
- func (sc *Client) GetLastWarning() string
- func (sc *Client) IsConnectError() bool
- func (sc *Client) Open() (err error)
- func (sc *Client) Query(query, index, comment string) (result *Result, err error)
- func (sc *Client) ResetFilters()
- func (sc *Client) ResetGroupBy()
- func (sc *Client) RunQueries() (results []Result, err error)
- func (sc *Client) SetConnectTimeout(timeout int) *Client
- func (sc *Client) SetFieldWeights(weights map[string]int) *Client
- func (sc *Client) SetFilter(attr string, values []uint64, exclude bool) *Client
- func (sc *Client) SetFilterFloatRange(attr string, fmin, fmax float32, exclude bool) *Client
- func (sc *Client) SetFilterRange(attr string, umin, umax uint64, exclude bool) *Client
- func (sc *Client) SetGeoAnchor(latitudeAttr, longitudeAttr string, latitude, longitude float32) *Client
- func (sc *Client) SetGroupBy(groupBy string, groupFunc int, groupSort string) *Client
- func (sc *Client) SetGroupDistinct(groupDistinct string) *Client
- func (sc *Client) SetIDRange(min, max uint64) *Client
- func (sc *Client) SetIndexWeights(weights map[string]int) *Client
- func (sc *Client) SetLimits(offset, limit, maxMatches, cutoff int) *Client
- func (sc *Client) SetMatchMode(mode int) *Client
- func (sc *Client) SetMaxQueryTime(maxQueryTime int) *Client
- func (sc *Client) SetOverride(attrName string, attrType int, values map[uint64]interface{}) *Client
- func (sc *Client) SetRankingMode(ranker int, rankexpr ...string) *Client
- func (sc *Client) SetRetries(count, delay int) *Client
- func (sc *Client) SetSelect(s string) *Client
- func (sc *Client) SetServer(host string, port int) *Client
- func (sc *Client) SetSortMode(mode int, sortBy string) *Client
- func (sc *Client) SetSqlServer(host string, sqlport int) *Client
- func (sc *Client) Status() (response [][]string, err error)
- func (sc *Client) UpdateAttributes(index string, attrs []string, values [][]interface{}, ignorenonexistent bool) (ndocs int, err error)
- type Connector
- type ExcerptsOpts
- type Keyword
- type Match
- type Options
- type Result
- type WordInfo
Constants ¶
const ( VER_MAJOR_PROTO = 0x1 VER_COMMAND_SEARCH = 0x119 // 0x11D for 2.1 VER_COMMAND_EXCERPT = 0x104 VER_COMMAND_UPDATE = 0x102 // 0x103 for 2.1 VER_COMMAND_KEYWORDS = 0x100 VER_COMMAND_STATUS = 0x100 VER_COMMAND_FLUSHATTRS = 0x100 )
searchd command versions
const ( SPH_MATCH_ALL = iota SPH_MATCH_ANY SPH_MATCH_PHRASE SPH_MATCH_BOOLEAN SPH_MATCH_EXTENDED SPH_MATCH_FULLSCAN SPH_MATCH_EXTENDED2 )
matching modes
const ( SPH_RANK_PROXIMITY_BM25 = iota // Default mode, phrase proximity major factor and BM25 minor one SPH_RANK_BM25 SPH_RANK_NONE SPH_RANK_WORDCOUNT SPH_RANK_PROXIMITY SPH_RANK_MATCHANY SPH_RANK_FIELDMASK SPH_RANK_SPH04 SPH_RANK_EXPR SPH_RANK_TOTAL )
ranking modes (extended2 only)
const ( SPH_SORT_RELEVANCE = iota SPH_SORT_ATTR_DESC SPH_SORT_ATTR_ASC SPH_SORT_TIME_SEGMENTS SPH_SORT_EXTENDED SPH_SORT_EXPR // Deprecated, never use it. )
sorting modes
const ( SPH_GROUPBY_DAY = iota SPH_GROUPBY_WEEK SPH_GROUPBY_MONTH SPH_GROUPBY_YEAR SPH_GROUPBY_ATTR SPH_GROUPBY_ATTRPAIR )
grouping functions
const ( SEARCHD_OK = iota SEARCHD_ERROR SEARCHD_RETRY SEARCHD_WARNING )
searchd reply status codes
const ( SPH_ATTR_NONE = iota SPH_ATTR_INTEGER SPH_ATTR_TIMESTAMP SPH_ATTR_ORDINAL SPH_ATTR_BOOL SPH_ATTR_FLOAT SPH_ATTR_BIGINT SPH_ATTR_STRING SPH_ATTR_MULTI = 0x40000001 SPH_ATTR_MULTI64 = 0x40000002 )
attribute types
const ( SEARCHD_COMMAND_SEARCH = iota SEARCHD_COMMAND_EXCERPT SEARCHD_COMMAND_UPDATE SEARCHD_COMMAND_KEYWORDS SEARCHD_COMMAND_PERSIST SEARCHD_COMMAND_STATUS SEARCHD_COMMAND_QUERY SEARCHD_COMMAND_FLUSHATTRS )
searchd commands
const ( SPH_FILTER_VALUES = iota SPH_FILTER_RANGE SPH_FILTER_FLOATRANGE )
filter types
Variables ¶
var DefaultOptions = &Options{ Host: "localhost", Port: 9312, SqlPort: 9306, Limit: 20, MatchMode: SPH_MATCH_EXTENDED, SortMode: SPH_SORT_RELEVANCE, GroupFunc: SPH_GROUPBY_DAY, GroupSort: "@group desc", MaxMatches: 1000, Timeout: 1000, RankMode: SPH_RANK_PROXIMITY_BM25, Select: "*", }
You can change it, so that you do not need to call Set***() every time.
Functions ¶
func EscapeString ¶
Types ¶
type Client ¶
type Client struct { *Options // For sphinxql DB *sql.DB // Capitalize, so that can "defer sc.Db.Close()" // contains filtered or unexported fields }
func (*Client) BuildExcerpts ¶
func (*Client) BuildKeywords ¶
Connect to searchd server, and generate keyword list for a given query. Returns null on failure, an array of Maps with misc per-keyword info on success.
func (*Client) FlushAttributes ¶
func (*Client) GetLastError ¶
func (*Client) GetLastWarning ¶
func (*Client) IsConnectError ¶
func (*Client) ResetFilters ¶
func (sc *Client) ResetFilters()
func (*Client) ResetGroupBy ¶
func (sc *Client) ResetGroupBy()
func (*Client) RunQueries ¶
Returns None on network IO failure; or an array of result set hashes on success.
func (*Client) SetConnectTimeout ¶
millisecond, not nanosecond.
func (*Client) SetFilterFloatRange ¶
func (*Client) SetFilterRange ¶
func (*Client) SetGeoAnchor ¶
func (sc *Client) SetGeoAnchor(latitudeAttr, longitudeAttr string, latitude, longitude float32) *Client
The latitude and longitude are expected to be in radians. Use DegreeToRadian() to transform degree values.
func (*Client) SetGroupBy ¶
func (*Client) SetGroupDistinct ¶
func (*Client) SetIDRange ¶
func (*Client) SetLimits ¶
Set matches offset and limit to return to client, max matches to retrieve on server, and cutoff.
func (*Client) SetMatchMode ¶
func (*Client) SetMaxQueryTime ¶
Set maximum query time, in milliseconds, per-index, 0 means "do not limit".
func (*Client) SetOverride ¶
func (*Client) SetRankingMode ¶
func (*Client) SetRetries ¶
func (*Client) SetServer ¶
Note: this func also can set sc.Socket(unix socket). You can just use ""/0 as default value.
func (*Client) UpdateAttributes ¶
func (sc *Client) UpdateAttributes(index string, attrs []string, values [][]interface{}, ignorenonexistent bool) (ndocs int, err error)
Connect to searchd server and update given attributes on given documents in given indexes. values[*][0] is docId, must be an uint64. values[*][1:] should be int or []int(mva mode) 'ndocs' -1 on failure, amount of actually found and updated documents (might be 0) on success
type ExcerptsOpts ¶
type ExcerptsOpts struct { BeforeMatch string // default is "<b>". AfterMatch string // default is "</b>". ChunkSeparator string // A string to insert between snippet chunks (passages). Default is " ... ". Limit int // Maximum snippet size, in symbols (codepoints). default is 256. Around int // How much words to pick around each matching keywords block. default is 5. ExactPhrase bool // Whether to highlight exact query phrase matches only instead of individual keywords. SinglePassage bool // Whether to extract single best passage only. UseBoundaries bool // Whether to additionaly break passages by phrase boundary characters, as configured in index settings with phrase_boundary directive. WeightOrder bool // Whether to sort the extracted passages in order of relevance (decreasing weight), or in order of appearance in the document (increasing position). QueryMode bool // Whether to handle $words as a query in extended syntax, or as a bag of words (default behavior). ForceAllWords bool // Ignores the snippet length limit until it includes all the keywords. LimitPassages int // Limits the maximum number of passages that can be included into the snippet. default is 0 (no limit). LimitWords int // Limits the maximum number of keywords that can be included into the snippet. default is 0 (no limit). StartPassageId int // Specifies the starting value of %PASSAGE_ID% macro (that gets detected and expanded in BeforeMatch, AfterMatch strings). default is 1. LoadFiles bool // Whether to handle $docs as data to extract snippets from (default behavior), or to treat it as file names, and load data from specified files on the server side. LoadFilesScattered bool // It assumes "load_files" option, and works only with distributed snippets generation with remote agents. The source files for snippets could be distributed among different agents, and the main daemon will merge together all non-erroneous results. So, if one agent of the distributed index has 'file1.txt', another has 'file2.txt' and you call for the snippets with both these files, the sphinx will merge results from the agents together, so you will get the snippets from both 'file1.txt' and 'file2.txt'. HtmlStripMode string // HTML stripping mode setting. Defaults to "index", allowed values are "none", "strip", "index", and "retain". AllowEmpty bool // Allows empty string to be returned as highlighting result when a snippet could not be generated (no keywords match, or no passages fit the limit). By default, the beginning of original text would be returned instead of an empty string. PassageBoundary string // Ensures that passages do not cross a sentence, paragraph, or zone boundary (when used with an index that has the respective indexing settings enabled). String, allowed values are "sentence", "paragraph", and "zone". EmitZones bool // Emits an HTML tag with an enclosing zone name before each passage. }
all bool values are default false.
type Options ¶
type Options struct { Host string Port int Socket string // Unix socket SqlPort int SqlSocket string RetryCount int RetryDelay int Timeout int Offset int // how many records to seek from result-set start Limit int // how many records to return from result-set starting at offset (default is 20) MaxMatches int // max matches to retrieve Cutoff int // cutoff to stop searching at MaxQueryTime int Select string // select-list (attributes or expressions, with optional aliases) MatchMode int // query matching mode (default is SPH_MATCH_ALL) RankMode int RankExpr string // ranking expression for SPH_RANK_EXPR SortMode int // match sorting mode (default is SPH_SORT_RELEVANCE) SortBy string // attribute to sort by (defualt is "") MinId uint64 // min ID to match (default is 0, which means no limit) MaxId uint64 // max ID to match (default is 0, which means no limit) LatitudeAttr string LongitudeAttr string Latitude float32 Longitude float32 GroupBy string // group-by attribute name GroupFunc int // group-by function (to pre-process group-by attribute value with) GroupSort string // group-by sorting clause (to sort groups in result set with) GroupDistinct string // group-by count-distinct attribute // for sphinxql Index string // index name for sphinxql query. Columns []string Where string }
type Result ¶
type Result struct { Fields []string // Full-text field namess. AttrNames []string // Attribute names. AttrTypes []int // Attribute types (refer to SPH_ATTR_xxx constants in Client). Matches []Match // Retrieved matches. Total int // Total matches in this result set. TotalFound int // Total matches found in the index(es). Time float32 // Elapsed time (as reported by searchd), in seconds. Words []WordInfo // Per-word statistics. Warning string Error error Status int // Query status (refer to SEARCHD_xxx constants in Client). }