Giter Site home page Giter Site logo

open-sstree's Introduction

open-sstree

Open Search Suggestion Tree - 搜索建议树

以谷歌为例,用户在输入过程中会提示通过前缀匹配的方式给出搜索的候选词条辅助用户补全输入

avatar

这个机制可以给用户非常快的搜索体验,同时也给用户提供候选输入,通过选择候选词条提交的query搜索引擎返回的结果相对会更精准(预设词条一般来自于历史搜索query)

核心原理

前缀树,拼音解析2个算法是本搜索建议算法的核心基石,加上大量的嵌套递归实现,目前已支持中文,英文,拼音,以及混合输入进行查找补全,完成搜索建议

数据结构如下图:

avatar

构建

启动时加载预设词条,逐行逐字读取default.dict,并且对中文字符添加相应的拼音索引以同时满足中文和拼音搜索

搜索

对输入的字符token做预处理,按照英文和非英文进行分token,然后逐个token逐字处理, 对中文部分逐字进行字符查找,英文部分进行字符查找+拼音查找, 整个是一个嵌套递归的过程,逐字查找候选节点,然后将候选节点传递给下一个token进一步查找的过程

运行

git clone https://github.com/chrwhy/open-pinyin.git

git clone https://github.com/chrwhy/open-sstree.git

cd open-sstree

go mod tidy

命令行模式

go run main.go
avatar

web模式(默认开启8081端口)

go run main.go web

keyword:搜索关键字

http://localhost:8081/search?keyword=pdf
avatar

二进制

CGO_ENABLED=0 GOOS=linux GOARCH=amd64
go build -o sstree_linux main.go

CGO_ENABLED=0 GOOS=windows GOARCH=amd64
go build -o sstree_win.exe main.go

CGO_ENABLED=0 GOOS=darwin GOARCH=amd64
go build -o sstree_mac main.go

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.