mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-27 23:12:20 +00:00
update dse
This commit is contained in:
parent
b97b4bac89
commit
f75bed0fc3
@ -83,6 +83,52 @@ func equal() {
|
||||
}
|
||||
```
|
||||
|
||||
就算文档总数很多,但我们的搜索词的倒排列表不长时,搜索速度也是很快的。如果用关系型数据库,那就需要按照索引(如果有的话)来慢慢扫描了。
|
||||
时间复杂度分析 TODO
|
||||
|
||||
在整个算法中起决定作用的一是最短的倒排列表的长度,其次是词数总和,一般词数不会很大(想像一下,你会在搜索引擎里输入几百字来搜索么?),所以起决定性作用的,一般是所有倒排列表中,最短的那一个的长度。
|
||||
|
||||
因此,文档总数很多的情况下,搜索词的倒排列表最短的那一个不长时,搜索速度也是很快的。如果用关系型数据库,那就需要按照索引(如果有的话)来慢慢扫描了。
|
||||
|
||||
### 查询 DSL
|
||||
|
||||
es 定义了一套查询 DSL,当我们把 es 当数据库使用时,需要用到其 bool 逻辑。举个例子:
|
||||
|
||||
```json
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": [{
|
||||
"match": {
|
||||
"field_1": {
|
||||
"query": "1",
|
||||
"type": "phrase"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"match": {
|
||||
"field_2": {
|
||||
"query": "2",
|
||||
"type": "phrase"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"match": {
|
||||
"field_3": {
|
||||
"query": "3",
|
||||
"type": "phrase"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"match": {
|
||||
"field_4": {
|
||||
"query": "4",
|
||||
"type": "phrase"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
},
|
||||
"from": 0,
|
||||
"size": 1
|
||||
}
|
||||
```
|
||||
|
Loading…
x
Reference in New Issue
Block a user