sonic 安装记录

 

https://github.com/valeriansaliou/sonic

$ rustc --version
rustc 1.50.0-dev

ubantu环境

rocksdb 安装依赖

apt install build-essential

apt install clang

apt install libclang-dev

apt install libc6-dev

apt install g++

apt install llvm-dev

 

rust换源

$ cd .cargo/
tanpengfei3@bage:~/.cargo$ ls
bin  config  env  registry
tanpengfei3@bage:~/.cargo$ cat config 
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
#registry = "git://mirrors.ustc.edu.cn/crates.io-index"
# 如果所处的环境中不允许使用 git 协议,可以把上面的地址改为
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

 

 git clone https://github.com/dbtool/sonic.git

 

配置文件

$ cat /etc/sonic/config.cfg 
# Sonic
# Fast, lightweight and schema-less search backend
# Configuration file
# Example: https://github.com/valeriansaliou/sonic/blob/master/config.cfg


[server]

log_level = "debug"


[channel]

inet = "127.0.0.1:1491"
tcp_timeout = 300

auth_password = "SecretPassword"

[channel.search]

query_limit_default = 10
query_limit_maximum = 100
query_alternates_try = 4

suggest_limit_default = 5
suggest_limit_maximum = 20


[store]

[store.kv]

path = "/opt/data/sonic/data/store/kv/"

retain_word_objects = 1000

[store.kv.pool]

inactive_after = 1800

[store.kv.database]

flush_after = 900

compress = true
parallelism = 2
max_files = 100
max_compactions = 1
max_flushes = 1
write_buffer = 16384
write_ahead_log = true

[store.fst]

path = "/opt/data/sonic/data/store/fst/"

[store.fst.pool]

inactive_after = 300

[store.fst.graph]

consolidate_after = 180

max_size = 2048
max_words = 250000

 

编辑

:/opt/wks/sonic$ cargo build
  Downloaded ahash v0.4.6 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded cc v1.0.61 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded getrandom v0.1.15 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded hashbrown v0.9.1 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded proc-macro2 v1.0.24 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded regex v1.4.1 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded regex-syntax v0.6.20 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded rocksdb v0.15.0 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded serde v1.0.116 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded serde_derive v1.0.116 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded syn v1.0.44 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded toml v0.5.7 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded aho-corasick v0.7.14 (registry `https://mirrors.ustc.edu.cn/crates.io-index`)
  Downloaded 13 crates (1.4 MB) in 4.19s
   Compiling libc v0.2.79
   Compiling cfg-if v0.1.10
   Compiling memchr v2.3.3
   Compiling proc-macro2 v1.0.24
   Compiling version_check v0.9.2
   Compiling bitflags v1.2.1
   Compiling glob v0.3.0
   Compiling unicode-xid v0.2.1
   Compiling lazy_static v1.4.0
   Compiling log v0.4.11
   Compiling unicode-width v0.1.8
   Compiling quick-error v1.2.3
   Compiling regex-syntax v0.6.20
   Compiling ansi_term v0.11.0
   Compiling bindgen v0.54.0
   Compiling vec_map v0.8.2
   Compiling strsim v0.8.0
   Compiling getrandom v0.1.15
   Compiling termcolor v1.1.0
   Compiling peeking_take_while v0.1.2
   Compiling byteorder v1.3.4
   Compiling lazycell v1.3.0
   Compiling shlex v0.1.1
   Compiling rustc-hash v1.1.0
   Compiling fs_extra v1.2.0
   Compiling autocfg v1.0.1
   Compiling serde v1.0.116
   Compiling ppv-lite86 v0.2.9
   Compiling syn v1.0.44
   Compiling utf8-ranges v1.0.4
   Compiling ahash v0.3.8
   Compiling nix v0.18.0
   Compiling serde_derive v1.0.116
   Compiling linked-hash-map v0.5.3
   Compiling regex-syntax v0.3.9
   Compiling ahash v0.4.6
   Compiling radix v0.6.0
   Compiling unicode-segmentation v1.6.0
   Compiling thread_local v1.0.1
   Compiling textwrap v0.11.0
   Compiling humantime v1.3.0
   Compiling nom v5.1.2
   Compiling clang-sys v0.29.3
   Compiling hashbrown v0.7.2
   Compiling linked_hash_set v0.1.4
   Compiling hashbrown v0.9.1
   Compiling aho-corasick v0.7.14
   Compiling quote v1.0.7
   Compiling whatlang v0.10.0
   Compiling regex v1.4.1
   Compiling jobserver v0.1.21
   Compiling atty v0.2.14
   Compiling which v3.1.1
   Compiling memmap v0.6.2
   Compiling cc v1.0.61
   Compiling clap v2.33.3
   Compiling env_logger v0.7.1
   Compiling cexpr v0.4.0
   Compiling rand_core v0.5.1
   Compiling fst v0.3.5
   Compiling rand_chacha v0.2.2
   Compiling fst-regex v0.2.2
   Compiling fst-levenshtein v0.2.1
   Compiling rand v0.7.3
   Compiling libloading v0.5.2
   Compiling jemalloc-sys v0.3.2
   Compiling toml v0.5.7
   Compiling twox-hash v1.5.0
   Compiling librocksdb-sys v6.11.4
   Compiling jemallocator v0.3.2
   Compiling rocksdb v0.15.0
   Compiling sonic-server v1.3.0 (/opt/wks/sonic)
    Finished dev [unoptimized + debuginfo] target(s) in 5m 37s

 

以root用户运行

root@bage:/opt/wks/sonic/target/debug# ./sonic -c /etc/sonic/config.cfg

 

go客户端

https://github.com/expectedsh/go-sonic

package main

import (
    "fmt"
    "github.com/expectedsh/go-sonic/sonic"
)

func main() {

    ingester, err := sonic.NewIngester("127.0.0.1", 1491, "SecretPassword")
    if err != nil {
        panic(err)
    }

    // I will ignore all errors for demonstration purposes

    _ = ingester.BulkPush("movies", "general", 3, []sonic.IngestBulkRecord{
        {"id:6ab56b4kk3", "Star wars"},
        {"id:5hg67f8dg5", "Spider man"},
        {"id:5hg67f8dg6", "super man"},
        {"id:1m2n3b4vf6", "Batman"},
        {"id:68d96h5h9d0", "This is another movie"},
    })

    search, err := sonic.NewSearch("127.0.0.1", 1491, "SecretPassword")
    if err != nil {
        panic(err)
    }

    results, _ := search.Query("movies", "general", "man", 10, 0)

    fmt.Println(results)
}

 

$ go run sc.go 
[id:5hg67f8dg6 id:5hg67f8dg5]

 

posted @ 2020-10-19 21:11  方诚  阅读(905)  评论(0编辑  收藏  举报