sphinxsearch

package
v0.0.0-...-203c0f7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

View Source
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)

View Source
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

View Source
const (
	SPH_GROUPBY_DAY = iota
	SPH_GROUPBY_WEEK
	SPH_GROUPBY_MONTH
	SPH_GROUPBY_YEAR
	SPH_GROUPBY_ATTR
	SPH_GROUPBY_ATTRPAIR
)

grouping functions

View Source
const (
	SEARCHD_OK = iota
	SEARCHD_ERROR
	SEARCHD_RETRY
	SEARCHD_WARNING
)

searchd reply status codes

View Source
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

View Source
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

View Source
const (
	SPH_FILTER_VALUES = iota
	SPH_FILTER_RANGE
	SPH_FILTER_FLOATRANGE
)

filter types

Variables

View Source
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 DegreeToRadian

func DegreeToRadian(degree float32) float32

For SetGeoAnchor()

func EscapeString

func EscapeString(s string) string

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 NewClient

func NewClient(opts ...*Options) (sc *Client)

func (*Client) AddQuery

func (sc *Client) AddQuery(query, index, comment string) (i int, err error)

func (*Client) BuildExcerpts

func (sc *Client) BuildExcerpts(docs []string, index, words string, opts ExcerptsOpts) (resDocs []string, err error)

func (*Client) BuildKeywords

func (sc *Client) BuildKeywords(query, index string, hits bool) (keywords []Keyword, err error)

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) Close

func (sc *Client) Close() error

func (*Client) Error

func (sc *Client) Error() error

Just for convenience

func (*Client) FlushAttributes

func (sc *Client) FlushAttributes() (iFlushTag int, err error)

func (*Client) GetLastError

func (sc *Client) GetLastError() error

func (*Client) GetLastWarning

func (sc *Client) GetLastWarning() string

func (*Client) IsConnectError

func (sc *Client) IsConnectError() bool

func (*Client) Open

func (sc *Client) Open() (err error)

func (*Client) Query

func (sc *Client) Query(query, index, comment string) (result *Result, err error)

func (*Client) ResetFilters

func (sc *Client) ResetFilters()

func (*Client) ResetGroupBy

func (sc *Client) ResetGroupBy()

func (*Client) RunQueries

func (sc *Client) RunQueries() (results []Result, err error)

Returns None on network IO failure; or an array of result set hashes on success.

func (*Client) SetConnectTimeout

func (sc *Client) SetConnectTimeout(timeout int) *Client

millisecond, not nanosecond.

func (*Client) SetFieldWeights

func (sc *Client) SetFieldWeights(weights map[string]int) *Client

func (*Client) SetFilter

func (sc *Client) SetFilter(attr string, values []uint64, exclude bool) *Client

func (*Client) SetFilterFloatRange

func (sc *Client) SetFilterFloatRange(attr string, fmin, fmax float32, exclude bool) *Client

func (*Client) SetFilterRange

func (sc *Client) SetFilterRange(attr string, umin, umax uint64, exclude bool) *Client

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 (sc *Client) SetGroupBy(groupBy string, groupFunc int, groupSort string) *Client

func (*Client) SetGroupDistinct

func (sc *Client) SetGroupDistinct(groupDistinct string) *Client

func (*Client) SetIDRange

func (sc *Client) SetIDRange(min, max uint64) *Client

func (*Client) SetIndexWeights

func (sc *Client) SetIndexWeights(weights map[string]int) *Client

func (*Client) SetLimits

func (sc *Client) SetLimits(offset, limit, maxMatches, cutoff int) *Client

Set matches offset and limit to return to client, max matches to retrieve on server, and cutoff.

func (*Client) SetMatchMode

func (sc *Client) SetMatchMode(mode int) *Client

func (*Client) SetMaxQueryTime

func (sc *Client) SetMaxQueryTime(maxQueryTime int) *Client

Set maximum query time, in milliseconds, per-index, 0 means "do not limit".

func (*Client) SetOverride

func (sc *Client) SetOverride(attrName string, attrType int, values map[uint64]interface{}) *Client

func (*Client) SetRankingMode

func (sc *Client) SetRankingMode(ranker int, rankexpr ...string) *Client

func (*Client) SetRetries

func (sc *Client) SetRetries(count, delay int) *Client

func (*Client) SetSelect

func (sc *Client) SetSelect(s string) *Client

func (*Client) SetServer

func (sc *Client) SetServer(host string, port int) *Client

Note: this func also can set sc.Socket(unix socket). You can just use ""/0 as default value.

func (*Client) SetSortMode

func (sc *Client) SetSortMode(mode int, sortBy string) *Client

func (*Client) SetSqlServer

func (sc *Client) SetSqlServer(host string, sqlport int) *Client

func (*Client) Status

func (sc *Client) Status() (response [][]string, err error)

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 Connector

type Connector struct {
	// contains filtered or unexported fields
}

func NewConnector

func NewConnector(opts *Options, cNum int) (*Connector, error)

func (*Connector) Close

func (cr *Connector) Close()

func (*Connector) Pull

func (cr *Connector) Pull() (cn *Client, err error)

func (*Connector) Push

func (cr *Connector) Push(cn *Client)

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 Keyword

type Keyword struct {
	Tokenized  string "Tokenized"
	Normalized string "Normalized"
	Docs       int
	Hits       int
}

type Match

type Match struct {
	DocId      uint64        // Matched document ID.
	Weight     int           // Matched document weight.
	AttrValues []interface{} // Matched document attribute values.
}

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).
}

type WordInfo

type WordInfo struct {
	Word string // Word form as returned from search daemon, stemmed or otherwise postprocessed.
	Docs int    // Total amount of matching documents in collection.
	Hits int    // Total amount of hits (occurences) in collection.
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL