tinysearch

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

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

Go to latest
Published: Jan 6, 2020 License: MIT Imports: 17 Imported by: 0

README

Tiny Search Engine

Search engine implemented in go

https://booth.pm/en/items/1576277

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

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

ポスティングリストをたどるためのカーソル

func (*Cursor) DocId

func (c *Cursor) DocId() DocumentID

func (*Cursor) Empty

func (c *Cursor) Empty() bool

func (*Cursor) Next

func (c *Cursor) Next()

func (*Cursor) NextDoc

func (c *Cursor) NextDoc(id DocumentID)

func (*Cursor) Posting

func (c *Cursor) Posting() *Posting

func (*Cursor) String

func (c *Cursor) String() string

type DocumentID

type DocumentID int64

ドキュメントID

type DocumentStore

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

func NewDocumentStore

func NewDocumentStore(db *sql.DB) *DocumentStore

type Engine

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

検索エンジン

func NewSearchEngine

func NewSearchEngine(db *sql.DB) *Engine

検索エンジンを作成する処理

func (*Engine) AddDocument

func (e *Engine) AddDocument(title string, reader io.Reader) error

インデックスにドキュメントを追加する

func (*Engine) Flush

func (e *Engine) Flush() error

インデックスをファイルに書き出す

func (*Engine) Search

func (e *Engine) Search(query string, k int) ([]*SearchResult, error)

検索を実行する

type Index

type Index struct {
	Dictionary     map[string]PostingsList // 辞書
	TotalDocsCount int                     // ドキュメントの総数
}

転地インデックス 注意: mapを使用しているのでマルチスレッドには対応していない

func NewIndex

func NewIndex() *Index

NewIndex create a new index.

func (Index) String

func (idx Index) String() string

type IndexReader

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

func NewIndexReader

func NewIndexReader(path string) *IndexReader

type IndexWriter

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

func NewIndexWriter

func NewIndexWriter(path string) *IndexWriter

func (*IndexWriter) Flush

func (w *IndexWriter) Flush(index *Index) error

インデックスをファイルに保存する

type Indexer

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

func NewIndexer

func NewIndexer(tokenizer *Tokenizer) *Indexer

type Posting

type Posting struct {
	DocID         DocumentID // ドキュメントID
	Positions     []int      // 用語の出現位置
	TermFrequency int        // ドキュメント内の用語の出現回数
}

ポスティング

func NewPosting

func NewPosting(docID DocumentID, positions ...int) *Posting

ポスティングを作成する

func (Posting) String

func (p Posting) String() string

type PostingsList

type PostingsList struct {
	*list.List
}

ポスティングリスト

func NewPostingsList

func NewPostingsList(postings ...*Posting) PostingsList

ポスティングリストを作成する処理

func (PostingsList) Add

func (pl PostingsList) Add(new *Posting)

ポスティングをリストに追加 ポスティングリストの最後を取得してドキュメントIDが 一致していなければ、ポスティングを追加 一致していれば、positionを追加

func (PostingsList) MarshalJSON

func (pl PostingsList) MarshalJSON() ([]byte, error)

func (PostingsList) OpenCursor

func (pl PostingsList) OpenCursor() *Cursor

func (PostingsList) String

func (pl PostingsList) String() string

func (*PostingsList) UnmarshalJSON

func (pl *PostingsList) UnmarshalJSON(b []byte) error

type ScoreDoc

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

ドキュメントIDそのドキュメントのスコアを保持する

func (ScoreDoc) String

func (d ScoreDoc) String() string

type SearchResult

type SearchResult struct {
	DocID DocumentID
	Score float64
	Title string
}

検索結果を格納する構造体

func (*SearchResult) String

func (r *SearchResult) String() string

String print SearchTopK result info

type Searcher

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

検索処理に必要なデータを保持する

func NewSearcher

func NewSearcher(path string) *Searcher

func (*Searcher) SearchTopK

func (s *Searcher) SearchTopK(query []string, k int) *TopDocs

検索を実行し、スコアが高い順にK件結果を返す

type Tokenizer

type Tokenizer struct{}

func NewTokenizer

func NewTokenizer() *Tokenizer

func (*Tokenizer) SplitFunc

func (t *Tokenizer) SplitFunc(data []byte, atEOF bool) (advance int, token []byte, err error)

io.Readerから読んだデータをトークンに分割する関数

func (*Tokenizer) TextToWordSequence

func (t *Tokenizer) TextToWordSequence(text string) []string

文字列を分解する処理

type TopDocs

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

searchTopKの検索結果を保持する

func (*TopDocs) String

func (t *TopDocs) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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