feat:完善项目信息

This commit is contained in:
henry
2022-01-20 11:51:02 +08:00
parent 9348c8970c
commit b87cd837be
23 changed files with 86 additions and 83 deletions

View File

@ -87,11 +87,12 @@ func TestNewInstance2(t *testing.T) {
service := client.Search().Index("es_patent_index")
result, err := service.Pretty(true).Query(query).Do(context.Background())
result, err := service.From(1).Size(1).TrackTotalHits(true).Pretty(true).Query(query).Do(context.Background())
if err != nil {
panic(err)
}
t.Log(utils.AnyToJSON(result.Hits.TotalHits.Value))
for _, v := range result.Hits.Hits {
t.Log(string(v.Source))
}

View File

@ -37,7 +37,7 @@ func Update(index, id string, body []byte) error {
}
// Search 搜索操作
func Search(src interface{}, index string, params *SearchParams, page, pageSize int) ([]interface{}, error) {
func Search(src interface{}, index string, params *SearchParams, page, pageSize int) ([]interface{}, int64, error) {
query := elastic.NewBoolQuery()
if params != nil {
@ -66,10 +66,10 @@ func Search(src interface{}, index string, params *SearchParams, page, pageSize
// 游标分页
service = service.From((page - 1) * pageSize).Size(pageSize)
}
result, err := service.Pretty(true).Query(query).Do(context.Background())
result, err := service.TrackTotalHits(true).Pretty(true).Query(query).Do(context.Background())
if err != nil {
return nil, err
return nil, 0, err
}
out := make([]interface{}, 0)
@ -79,11 +79,11 @@ func Search(src interface{}, index string, params *SearchParams, page, pageSize
_src := reflect.New(_type).Interface()
if err = json.Unmarshal(hit.Source, _src); err != nil {
return nil, err
return nil, 0, err
}
out = append(out, _src)
}
return out, err
return out, result.Hits.TotalHits.Value, err
}
// Delete 删除操作