se

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 18, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

README

Search Engines

个人文件、目录搜索引擎

安装方法

go get -u gitee.com/xuender/se/cmd/se

核心功能 v1.0

  • 忽略大小写
    • 驼峰分词
    • 下划线分词
    • 大写的英文缩写
  • 词搜索
    • 显示命中结果
    • 分页显示
    • 新增词组
  • 词组转换词搜索
  • 文件包含的词
  • 词关联的文件
  • 词列表
    • 词列表分页
    • 词索引占用磁盘空间
  • 文件列表
    • 文件列表分页
    • 文件中词的数量
    • 文件索引占用磁盘空间
  • 文件索引
    • 目录索引
  • 配置文件
    • 扩展文件名设置
    • 忽略目录
  • 文件词查询
  • 词关联文件查询
  • 文件索引
    • 子目录不记录
  • 重新扫描
    • 根据目录变化查找文件变化
    • 文件删除

后续工作 v1.1

  • 文件服务独立
  • 词服务独立
  • 词长度限制
  • 索引服务独立
  • 图形界面
  • 大文件搜索结果快速预览
  • 禁用词
  • 词删除
  • 内置词库
  • 词组信息,搜索次数,创建时间
  • 删除文件ID重使用
  • 文件ID重排
  • 删除词ID重使用
  • 词ID重排
  • 词频,词组频率分析
  • 根据词频进行重新修改词ID

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrFileChange = errors.New("文件发生修改,请索引")

ErrFileChange 文件发生修改.

Functions

func FormatFileSize

func FormatFileSize(size int64) string

FormatFileSize 格式化文件尺寸.

Example
package main

import (
	"fmt"

	"gitee.com/xuender/se"
)

func main() {
	fmt.Println(se.FormatFileSize(2048))
	fmt.Println(se.FormatFileSize(2))
	fmt.Println(se.FormatFileSize(71002048))
	fmt.Println(se.FormatFileSize(1024*1024*1024 + 1))
	fmt.Println(se.FormatFileSize(1024 * 1024 * 1024 * 1024 * 5))
	fmt.Println(se.FormatFileSize(1024 * 1024 * 1024 * 1024 * 1024 * 5))

}
Output:

2KB
2B
67.71MB
1.00GB
5.00TB
5.00EB

func Hits

func Hits(text string, words []string) []*pb.Hit

Hits 命中.

func Index

func Index(lower, str, word string) (int, int)

Index 位置.

func IsWord

func IsWord(r rune) bool

IsWord 是否是字.

func NewDB

func NewDB(config *Config) level.DB

NewDB 新建数据库.

func Size

func Size(file string) int64

Size 目录或文件尺寸.

Example
package main

import (
	"fmt"

	"gitee.com/xuender/se"
)

func main() {
	fmt.Println(se.FormatFileSize(se.Size("test.go")))
	fmt.Println(se.FormatFileSize(se.Size("size_test.go")))
	fmt.Println(se.FormatFileSize(se.Size("pb")))

}
Output:

0B
685B
18KB

func Split

func Split(txt string) sets.Strings

Split 分词.

func SplitWord

func SplitWord(elems []string) sets.Strings

SplitWord 拆分词,如: IsWord 拆分 is, word.

func WordsMay

func WordsMay(words string) []string

WordsMay 词组的可能存在形式.

Types

type App

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

App 应用.

func InitApp

func InitApp(c *Config) *App

InitApp 初始化客户端应用.

func NewApp

func NewApp(
	ss *Service,
	config *Config,
) *App

NewApp 新建应用.

func (*App) Close

func (p *App) Close() error

Close 关闭.

func (*App) File

func (p *App) File(file string)

File 文件详情.

func (*App) Files

func (p *App) Files()

Files 索引文件列表.

func (*App) Index

func (p *App) Index(files []string)

Index 索引文件或目录.

func (*App) Min added in v1.0.3

func (p *App) Min()

Min 缩小索引.

func (*App) Reindex

func (p *App) Reindex()

Reindex 重新索引.

func (*App) Search

func (p *App) Search(words []string)

Search 搜索.

func (*App) Word

func (p *App) Word(word string)

Word 词详情.

func (*App) Words

func (p *App) Words()

Words 词列表.

type Config

type Config struct {
	DataBasePath string
	Deploy       bool
	Limit        uint   `toml:"-"`
	Offset       uint   `toml:"-"`
	Start        string `toml:"-"`
	Exts         []string
	Ignore       []string
	PassDir      bool
}

Config 设置.

func NewConfig

func NewConfig() *Config

NewConfig 新建配置.

func (*Config) Chack

func (p *Config) Chack()

Chack 配置检查.

func (*Config) Read

func (p *Config) Read(cmd *cobra.Command)

Read 从命令行中读取配置.

func (*Config) Save

func (p *Config) Save()

Save 保存配置.

type FileService added in v1.0.3

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

FileService 文件服务.

func NewFileService added in v1.0.3

func NewFileService(
	config *Config,
	ls *level.Service,
) *FileService

NewFileService 新建文件服务.

func (*FileService) Delete added in v1.0.3

func (p *FileService) Delete(file string)

Delete 删除文件.

func (*FileService) File added in v1.0.3

func (p *FileService) File(file string) (*pb.File, bool)

File 生成文件信息.

func (*FileService) FileByWord added in v1.0.3

func (p *FileService) FileByWord(ids []uint32) []uint32

FileByWord 根据词ID查找文件信息.

func (*FileService) Files added in v1.0.3

func (p *FileService) Files(ids []uint32) []*pb.File

Files 根据文件ID返回文件信息.

func (*FileService) FilesByStart added in v1.0.3

func (p *FileService) FilesByStart(start string) []*pb.File

FilesByStart 索引文件列表.

func (*FileService) Hit added in v1.0.3

func (p *FileService) Hit(file *pb.File, words []string)

Hit 命中.

func (*FileService) Tag added in v1.0.3

func (p *FileService) Tag(fid uint32, ts tags.Tags)

Tag 给文件打标签.

type IndexData added in v1.0.3

type IndexData struct {
	ID    uint32
	Count int
	Name  string
}

IndexData 索引数据.

type Indexs added in v1.0.3

type Indexs []*IndexData

Indexs 索引数据.

func (Indexs) Len added in v1.0.3

func (p Indexs) Len() int

func (Indexs) Less added in v1.0.3

func (p Indexs) Less(i, j int) bool

func (Indexs) Swap added in v1.0.3

func (p Indexs) Swap(i, j int)

type Service

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

Service 搜索引擎服务.

func NewService

func NewService(
	config *Config,
	ls *level.Service,
	fs *FileService,
	ws *WordService,
) *Service

NewService 新建搜索引擎服务.

func (*Service) Close

func (p *Service) Close() error

Close 关闭.

func (*Service) FileInfo

func (p *Service) FileInfo(file string) *pb.File

FileInfo 文件信息.

func (*Service) FindWords

func (p *Service) FindWords(fileIDs []uint32, words string) []uint32

FindWords 根据文件ID和词组,查找包含词ID.

func (*Service) Index

func (p *Service) Index(path string)

Index 索引文件或目录.

func (*Service) Min added in v1.0.3

func (p *Service) Min()

Min 索引缩小.

func (*Service) Reindex

func (p *Service) Reindex()

Reindex 重新索引.

func (*Service) Search

func (p *Service) Search(wordses []string) []*pb.File

Search 搜索.

func (*Service) WordInfo

func (p *Service) WordInfo(word string) *pb.Word

WordInfo 词信息.

func (*Service) WordList

func (p *Service) WordList(start string) []*pb.Word

WordList 词列表.

type WordService added in v1.0.3

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

WordService 词服务.

func NewWordService added in v1.0.3

func NewWordService(ls *level.Service) *WordService

NewWordService 新建词服务.

func (*WordService) Word added in v1.0.3

func (p *WordService) Word(word string, create bool) uint32

Word 词的主键.

func (*WordService) Words added in v1.0.3

func (p *WordService) Words(ids []uint32) []*pb.Word

Words 根据id获取词信息.

Directories

Path Synopsis
cmd
se
txt

Jump to

Keyboard shortcuts

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