goose

package module
v0.0.0-...-a05fd75 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2014 License: MIT Imports: 12 Imported by: 0

README

#goose goose是使用golang开发检索框架,目标是打造一个简单方便使用的小型检索系统. 期望解决百万量级doc数量的检索问题.

goose这个名称的由来: 由于是使用golang开发的search engine,一开始想到就是用gose这个单词,但是其没有什么 含义,突然发现往中间加多一个字母o,就形成了一个有意义的单词 goose ,另外想到 很多牛X的项目(或语言)都以动物名字来命名,所以觉得 goose 这个名字挺好.

##如何使用? goose是一个检索框架实现,由几个基础模块组成:

  • database负责底层的静态索引,动态索引,ID管理,Value管理,Data管理.
  • config模块简单实现的用于读取配置的模块.
  • log是日志模块的封装.
  • utils包含了goose的基础类型定义以及其它一些小工具类.
  • GooseBuild.goIndexer.go是主要的建库流程实现.
  • GooseSearch.goSearcher.go是主要的检索流程实现.
  • IStrategy.go是检索策略需要关注以及实现的细节.

###策略实现 使用goose开发(小型的)检索系统,需要实现IStrategy.go所定义的策略. goose-demo是一个实现demo,它演示了如果使用goose进行二次开发. ###零编码 为了更加方便,快速搭建一个检索系统,cse是正在开发中的一个项目,它基于goose实现了一个零编码的小型通用检索系统,只要修改配置,按照要求的格式准备好输入数据,就可以直接建库后提供检索服务.
目前,还在开发中...

##goose的设计 开了个头,争取把详解goose的系列文章写完

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocIterator

type DocIterator interface {
	// 获取下个待索引的doc,返回nil表示迭代结束.
	NextDoc() interface{}
}

type Goose

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

goose的入口程序.

func NewGoose

func NewGoose() *Goose

func (*Goose) Run

func (this *Goose) Run()

程序入口,解析程序参数,启动[建库|检索]模式

func (*Goose) SetIndexStrategy

func (this *Goose) SetIndexStrategy(sty IndexStrategy)

func (*Goose) SetSearchStrategy

func (this *Goose) SetSearchStrategy(sty SearchStrategy)

type GooseBuild

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

Goose的静态库生成程序.

func NewGooseBuild

func NewGooseBuild() *GooseBuild

func (*GooseBuild) Init

func (this *GooseBuild) Init(confPath string, indexSty IndexStrategy, toIndexFile string) (err error)

根据配置文件进行初始化. 需要外部指定索引策略,策略可以重新设计. 需要外部知道被索引文件(这个易变信息不适合放配置)

func (*GooseBuild) Run

func (this *GooseBuild) Run() (err error)

type GooseSearch

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

Goose检索程序.核心工作是提供检索服务,同时支持动态插入索引.

func NewGooseSearch

func NewGooseSearch() *GooseSearch

func (*GooseSearch) Init

func (this *GooseSearch) Init(confPath string,
	indexSty IndexStrategy, searchSty SearchStrategy) (err error)

func (*GooseSearch) Run

func (this *GooseSearch) Run() error

type IndexStrategy

type IndexStrategy interface {
	// 全局初始化的接口
	Init(conf config.Conf) error

	// 分析一个doc,返回其中的term列表,Value,Data
	ParseDoc(doc interface{}, context *StyContext) (OutIdType, []TermInDoc, Value, Data, error)
}

建索引策略. 框架会调用一次Init接口进行初始化,建索引的时候会N个goroutine调用ParseDoc

type MergeEngine

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

func NewMergeEngine

func NewMergeEngine(db DataBaseReader, termList []TermInQuery) (*MergeEngine, error)

func (*MergeEngine) Next

func (this *MergeEngine) Next(termInDoclist []TermInDoc) (inId InIdType, currValid, allfinish bool)

type SearchStrategy

type SearchStrategy interface {
	// 全局初始化的接口
	Init(conf config.Conf) error

	// 解析请求
	// 返回term列表,一个由策略决定的任意数据,后续接口都会透传
	ParseQuery(request []byte, context *StyContext) ([]TermInQuery, interface{}, error)

	// 对一个结果进行打分,确定相关性
	// queryInfo    : ParseQuery策略返回的结构
	// inId         : 需要打分的doc的内部id
	// outId        : 需求打分的doc的外部id
	// termInQuery  : 所有term在query中的打分
	// termInDoc    : 所有term在doc中的打分
	// termCnt      : term数量
	// Weight       : 返回doc的相关性得分
	// 返回错误当前结果则丢弃
	// @NOTE query中的term不一定能命中doc,TermInDoc.Weight == 0表示这种情况
	CalWeight(queryInfo interface{}, inId InIdType, outId OutIdType,
		termInQuery []TermInQuery, termInDoc []TermInDoc,
		termCnt uint32, context *StyContext) (TermWeight, error)

	// 合并三个最初的接口(Filt,Adjust,Response)为一个
	// 划分的几个接口,只是给策略增加不必要的麻烦,修改全部开放给策略自定义实现
	Response(queryInfo interface{},
		list SearchResultList,
		valueReader ValueReader,
		dataReader DataReader,
		response []byte,
		context *StyContext) (reslen int, err error)
}

type Searcher

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

func NewSearcher

func NewSearcher(db DataBaseReader, sty SearchStrategy) (*Searcher, error)

func (*Searcher) Search

func (this *Searcher) Search(context *StyContext, reqbuf []byte, resbuf []byte) (reslen int, err error)

type StaticIndexer

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

静态索引生成类.

func NewStaticIndexer

func NewStaticIndexer(db DataBaseWriter, sty IndexStrategy) (*StaticIndexer, error)

func (*StaticIndexer) BuildIndex

func (this *StaticIndexer) BuildIndex(iter DocIterator) error

并发多个协程分析doc,最终阻塞完成写入db后返回

type StyContext

type StyContext struct {
	// 供策略打日志使用
	Log *log.GooseLogger
}

func NewStyContext

func NewStyContext() *StyContext

创建新的

func (*StyContext) Clear

func (this *StyContext) Clear()

重置后可以重用

func (*StyContext) Clone

func (this *StyContext) Clone() *StyContext

克隆,能复用的尽量复用

type VarIndexer

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

动态索引生成类.

func NewVarIndexer

func NewVarIndexer(db DataBaseWriter, sty IndexStrategy) (*VarIndexer, error)

func (*VarIndexer) BuildIndex

func (this *VarIndexer) BuildIndex(iter DocIterator) error

单协程完成工作,分析doc然后写入索引结束.

Notes

Directories

Path Synopsis
log的简单封装 我所期待的log接口(我在工作环境熟悉的)是这样的: 1.
log的简单封装 我所期待的log接口(我在工作环境熟悉的)是这样的: 1.
Package utils 是goose中的一个公共包,存放的是公共类型的定义和一些基础工具.
Package utils 是goose中的一个公共包,存放的是公共类型的定义和一些基础工具.

Jump to

Keyboard shortcuts

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