feat:完成首页搜索功能

This commit is contained in:
henry
2022-01-18 16:29:29 +08:00
parent 478182dcb0
commit 10224e8db6
21 changed files with 572 additions and 167 deletions

View File

@ -73,21 +73,21 @@ func Search(src interface{}, index string, params *SearchParams, page, pageSize
}
out := make([]interface{}, 0)
_type := reflect.TypeOf(src)
_type := reflect.TypeOf(src).Elem()
for _, hit := range result.Hits.Hits {
data := reflect.New(_type).Interface()
_src := reflect.New(_type).Interface()
if err = json.Unmarshal(hit.Source, data); err != nil {
if err = json.Unmarshal(hit.Source, _src); err != nil {
return nil, err
}
out = append(out, data)
out = append(out, _src)
}
return out, err
}
// Delete 删除操作
func Delete(index string) error {
_, err := client.DeleteIndex(index).Do(context.Background())
func Delete(index, id string) error {
_, err := client.Delete().Index(index).Do(context.Background())
return err
}