search

package module
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 11 Imported by: 4 modules, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

search 是 infrago 的模块。

包定位

  • 类型:模块
  • 作用:搜索模块,负责统一检索接口与多搜索后端适配。

主要功能

  • 对上提供统一模块接口
  • 对下通过驱动接口接入具体后端
  • 支持按配置切换驱动实现

快速接入

import _ "github.com/infrago/search"
[search]
driver = "default"

驱动实现接口列表

以下接口由驱动实现(来自模块 driver.go):

Driver
  • Connect(*Instance) (Connection, error)
Connection
  • Open() error
  • Close() error
  • Capabilities() Capabilities
  • SyncIndex(name string, index Index) error
  • Clear(index string) error
  • Upsert(index string, rows []Map) error
  • Delete(index string, ids []string) error
  • Search(index string, query Query) (Result, error)
  • Count(index string, query Query) (int64, error)

全局配置项(所有配置键)

配置段:[search]

  • 未检测到配置键(请查看模块源码的 configure 逻辑)

说明

  • setting 一般用于向具体驱动透传专用参数
  • 多实例配置请参考模块源码中的 Config/configure 处理逻辑

Documentation

Index

Constants

View Source
const (
	FilterEq    = "eq"
	FilterNe    = "ne"
	FilterGt    = "gt"
	FilterGte   = "gte"
	FilterLt    = "lt"
	FilterLte   = "lte"
	FilterIn    = "in"
	FilterNin   = "nin"
	FilterRange = "range"
)

Variables

This section is empty.

Functions

func Clear

func Clear(index string) error

func Count

func Count(index, keyword string, args ...Any) (int64, error)

func Delete

func Delete(index string, ids []string) error

func FilterMatch

func FilterMatch(filter Filter, payload Map) bool

func ListCapabilities

func ListCapabilities() map[string]Capabilities

func QuerySignature

func QuerySignature(index string, q Query) string

func Signature

func Signature(index, keyword string, args ...Any) string

func Upsert

func Upsert(index string, rows ...Map) error

Types

type Capabilities

type Capabilities struct {
	SyncIndex bool
	Clear     bool
	Upsert    bool
	Delete    bool
	Search    bool
	Count     bool
	Suggest   bool

	Sort      bool
	Facets    bool
	Highlight bool

	FilterOps []string
}

func GetCapabilities

func GetCapabilities(index string) Capabilities

type Config

type Config struct {
	Driver  string
	Weight  int
	Prefix  string
	Timeout time.Duration
	Setting Map
}

type Configs

type Configs map[string]Config

type Connection

type Connection interface {
	Open() error
	Close() error

	Capabilities() Capabilities
	SyncIndex(name string, index Index) error
	Clear(index string) error
	Upsert(index string, rows []Map) error
	Delete(index string, ids []string) error
	Search(index string, query Query) (Result, error)
	Count(index string, query Query) (int64, error)
}

type Driver

type Driver interface {
	Connect(*Instance) (Connection, error)
}

type Facet

type Facet struct {
	Field string
	Value string
	Count int64
}

type Filter

type Filter struct {
	Field  string
	Op     string
	Value  Any
	Values []Any
	Min    Any
	Max    Any
}

type Hit

type Hit struct {
	ID        string  `json:"id"`
	Score     float64 `json:"score"`
	Payload   Map     `json:"payload"`
	Highlight Map     `json:"highlight,omitempty"`
}

type Index

type Index struct {
	Name        string
	Desc        string
	Primary     string
	Attributes  Vars
	StrictWrite bool
	StrictRead  bool
	Fields      Map
	Language    string
	Analyzer    string
	Setting     Map
}

type Indexes

type Indexes map[string]Index

type Instance

type Instance struct {
	Name    string
	Config  Config
	Setting Map
	// contains filtered or unexported fields
}

type Module

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

func (*Module) Capabilities

func (m *Module) Capabilities(index string) Capabilities

func (*Module) Clear

func (m *Module) Clear(index string) error

func (*Module) Close

func (m *Module) Close()

func (*Module) Config

func (m *Module) Config(global Map)

func (*Module) Count

func (m *Module) Count(index, keyword string, args ...Any) (int64, error)

func (*Module) Delete

func (m *Module) Delete(index string, ids []string) error

func (*Module) Health added in v0.30.0

func (m *Module) Health() infra.ModuleHealth

func (*Module) ListCapabilities

func (m *Module) ListCapabilities() map[string]Capabilities

func (*Module) Open

func (m *Module) Open()

func (*Module) Ready added in v0.30.0

func (m *Module) Ready() bool

func (*Module) Register

func (m *Module) Register(name string, value Any)

func (*Module) RegisterConfig

func (m *Module) RegisterConfig(name string, cfg Config)

func (*Module) RegisterConfigs

func (m *Module) RegisterConfigs(configs Configs)

func (*Module) RegisterDriver

func (m *Module) RegisterDriver(name string, driver Driver)

func (*Module) RegisterIndex

func (m *Module) RegisterIndex(name string, index Index)

func (*Module) RegisterIndexes

func (m *Module) RegisterIndexes(indexes Indexes)

func (*Module) Search

func (m *Module) Search(index, keyword string, args ...Any) (Result, error)

func (*Module) Setup

func (m *Module) Setup()

func (*Module) Start

func (m *Module) Start()

func (*Module) Stats added in v0.30.0

func (m *Module) Stats() infra.ModuleStats

func (*Module) Stop

func (m *Module) Stop()

func (*Module) Upsert

func (m *Module) Upsert(index string, rows ...Map) error

type Query

type Query struct {
	Keyword   string
	Prefix    bool
	Filters   []Filter
	Sorts     []Sort
	Offset    int
	Limit     int
	Fields    []string
	Facets    []string
	Highlight []string
	Raw       Map
	Setting   Map
}

func BuildQuery

func BuildQuery(keyword string, args ...Any) Query

type Result

type Result struct {
	Total  int64              `json:"total"`
	Took   int64              `json:"took"`
	Hits   []Hit              `json:"hits"`
	Facets map[string][]Facet `json:"facets,omitempty"`
	Raw    Any                `json:"raw,omitempty"`
}
func Search(index, keyword string, args ...Any) (Result, error)

type Sort

type Sort struct {
	Field string
	Desc  bool
}

Jump to

Keyboard shortcuts

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