@@ -0,0 +1,105 @@
|
||||
package audioanchormod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"91porn-server/common/elastic"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/models"
|
||||
)
|
||||
|
||||
var es *elastic.Client
|
||||
|
||||
const ESTable = models.ESInfoLouFengTable
|
||||
|
||||
func InitESIndex() {
|
||||
es = elastic.Init()
|
||||
var setting = elastic.M{
|
||||
"settings": elastic.M{
|
||||
"number_of_shards": elastic.NumberOfShards,
|
||||
"number_of_replicas": elastic.NumberOfReplicas,
|
||||
"analysis": elastic.M{
|
||||
"analyzer": elastic.M{
|
||||
"ik": elastic.M{
|
||||
"tokenizer": elastic.AnalyzerIkMaxWord,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"mappings": elastic.M{
|
||||
"properties": elastic.M{
|
||||
"age": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
"price": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
|
||||
"title": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
"city": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
"district": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
"impression": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
"contact": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkSmart,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
"serviceItems": elastic.M{
|
||||
"type": "text",
|
||||
"analyzer": elastic.AnalyzerIkMaxWord,
|
||||
"search_analyzer": elastic.AnalyzerIkSmart,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if err := es.CreateIndices(ESTable, setting); err != nil {
|
||||
panic(fmt.Sprintf("%s index indeices err ==>[%+v]", ESTable, err))
|
||||
}
|
||||
}
|
||||
|
||||
func Search(keywords string, from int64, size int64) (data []ESUserSource, err error) {
|
||||
query := elastic.M{
|
||||
"query": elastic.M{
|
||||
"bool": elastic.M{
|
||||
"must": elastic.A{
|
||||
{"multi_match": elastic.M{
|
||||
"query": keywords,
|
||||
"fields": []string{"city", "impression", "title", "serviceItems", "price"}},
|
||||
},
|
||||
{"term": elastic.M{"isActive": true}},
|
||||
},
|
||||
},
|
||||
},
|
||||
"from": from,
|
||||
"size": size,
|
||||
}
|
||||
if err = es.Search(ESTable, &data, query); err != nil {
|
||||
log.Error(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "Search", table, "CommonSearch", err),
|
||||
log.Any("keywords", keywords),
|
||||
log.Any("from", from),
|
||||
log.Any("size", size),
|
||||
)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user