• Stars
    star
    180
  • Rank 213,097 (Top 5 %)
  • Language
    JavaScript
  • Created about 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

搜索输入框-下拉提示(推荐), 提示词根据权重排序.基于double-array-trie的darts, golang语言实现.

suggestion

简单的输入框下拉提示服务

简介

在搜索输入框等位置,用户输入关键词,系统提示可以使用的关键字,提升用户体验

截图

img

依赖

  1. jquery-2.1.1.min.js

  2. twitter typeahead 0.10.5 github | examples

使用

  1. clone

  2. go run test_web.go

  3. http://localhost:9090

  4. input


数据文件格式

默认文件格式:

format:    word\tweight
coding:    utf-8 [must]
require:   weight type(int)

eg:  植物大战僵尸\t1000

实现方式1: easymap

使用map方式实现树结构,有python和golang两个版本(见easymap子目录)

quick run:

git clone https://github.com/wklken/suggestion.git
cd suggestion/easymap
python suggest.py
go run suggest.go
适用: 小型系统, 关键词在 10W 左右(中文+拼音+拼音首字母共30W左右)
优点: 逻辑简单结构清晰, 代码足够少, 方便扩展(e.g. 可自行修改存储结构,在返回中加入图片等额外信息)
缺点: 内存占用,30W关键词,平均词长3,占用800M内存, 另外对cpu也有一定消耗
处理和实践: 
      python版本 加一层redis/memcached, python版本, 单机8进程, 16核, 占用1G内存, 每天总请求量在300-500w左右, qps峰值在 300 左右, 没什么压力[没做过压测....]
      golang版本完全没在生产上试过, 应该毫无压力

实现方式2: double-array-trie

使用实现了double-array-trie的darts实现,golang代码

darts实现参考项目: awsong/go-darts

double-array-trie文章: What is Trie | An Implementation of Double-Array Trie

quick run

go run test_web.go
访问 http://localhost:9090

or 

 go run test_run.go

input dict length: 29
build out length 65708
3.55us
<nil>
搜索: 植物大战
Result Len: 10
植物大战僵尸 154717704
植物大战僵尸年度中文版 44592048
植物大战僵尸OL 43566752
植物大战僵尸2 630955
植物大战外星人 530403
植物大战怪兽 29727
植物大战异形变态版 14773
植物大战臭虫 5999
植物大战异形 4456
植物大战昆虫2无敌版 3419
适用: 关键词在10w 以上的系统
优点: 内存占用小, 性能保证
缺点: 底层依赖double-array-trie,逻辑有点绕,自定义不是很方便
处理和实践: 加一层redis/memcached

TODO

集中于darts版本(easymap分离出去)
1.性能测试
2.数据结构可自定义
3.容错处理
4.大小写,拼音,首字母等处理

Change Log

2013-10-13 created, python版本
2013-12-14 增加golang版本
2014-05-11 增加double-array-trie实现的golang 版本
2014-11-04 fix golang version bug, 增加前端展示

Donation

如果你觉得我的项目对你有所帮助, You can buy me a coffee:)

donation


wklken(Pythonista/Vimer)

Email: [email protected]

Blog: http://www.wklken.me

Github: https://github.com/wklken

2013-10-13 于深圳

More Repositories

1

k-vim

vim配置
Vim Script
4,895
star
2

stackoverflow-py-top-qa

stackoverflow上Python相关回答整理翻译
855
star
3

vim-for-server

.vimrc, simple configures for server, without plugins.
Vim Script
603
star
4

py-patterns

设计模式的python实现
Python
408
star
5

config

My linux config file. .bash_profile .alias bin .vimrc etc.
Shell
170
star
6

k-tmux

tmux.conf
91
star
7

bash-utils

utils for shell
Shell
80
star
8

pytools

Some powerful scripts and tools wrote by Python! Impressive
Python
67
star
9

linux-notes

Some quick intro notebook of linux for Chinese Programmers
58
star
10

Python-2.7.8

Python源码注释版本
Python
47
star
11

k-vim-vscode

vscode settings with vim key-bindings just like k-vim(https://github.com/wklken/k-vim)! Happy Coding!
41
star
12

pyutils

A lot of useful functions/modules.
Python
29
star
13

naming

Naming is the most difficult part of programming, this repo may save your time.
Python
26
star
14

cmdcheatsheet

A quick cheatsheet tool in shell, you can use keyword to reach what you edit/need!
Python
25
star
15

KeepLearning

之前学习一些东西的代码集合, 一般跟某份教程或者某本书一致. 代码+详细注释, 可执行
Python
21
star
16

fetch

A command line http test tool. Maintain the case via git and pure text
Go
17
star
17

apue.3e

apue.3e 注释版本
C
10
star
18

http_json_logger

Golang. To get json body from http api, write to json file, and do rotate daily. The log file will be used for logstash json_lines
Go
5
star
19

flask-qrcode-demo

flask + python-qrcode, a simple service demo:)
Python
4
star
20

dataformat

A tool to generate data or reformat source data to csv/xml, useful for test data
Python
4
star
21

rabbitmq-http-dispatcher

An simple consumer, dispatch messages to http server.
Python
3
star
22

echo

An server will echo the requests detail into response. For api testing / benchmark for your proxies like APIGateway/ReverseProxy/nginx/traefik.
Go
2
star
23

logging-go

A practical and high-performance go logging lib, based on logrus, with a lot of hooks
Go
2
star
24

wklken.github.io

个人博客
HTML
1
star
25

flask_dir_gen

A shell script to generate flask project dir.
Python
1
star
26

offline

Install virtualenv and supervisord to a system without internet access(offline)
Shell
1
star
27

apisix-extra-plugins

some plugins
Lua
1
star
28

apisix-go

This is an `apisix` implemented via Go
Go
1
star