根据id查询搜索数据结构 @param id 根据id查询搜索文档
(id ...int)
| 386 | //根据id查询搜索数据结构 |
| 387 | //@param id 根据id查询搜索文档 |
| 388 | func (this *Document) GetDocForElasticSearch(id ...int) (es []ElasticSearchData, err error) { |
| 389 | var ( |
| 390 | sql string |
| 391 | params []orm.Params |
| 392 | num int64 |
| 393 | ) |
| 394 | tables := []string{GetTableDocumentInfo() + " i", GetTableDocument() + " d", GetTableDocumentStore() + " ds"} |
| 395 | on := []map[string]string{ |
| 396 | {"i.Id": "d.Id"}, |
| 397 | {"i.DsId": "ds.Id"}, |
| 398 | } |
| 399 | fields := map[string][]string{ |
| 400 | "i": {"Score", "Id", "Dcnt", "Vcnt", "Ccnt", "Price", "TimeCreate"}, |
| 401 | "d": {"Title", "Description", "Keywords"}, |
| 402 | "ds": {"Page", "Size", "ExtNum DocType", "Id DsId"}, |
| 403 | } |
| 404 | listRows := len(id) |
| 405 | if listRows == 0 { |
| 406 | err = errors.New("请至少传递一个文档Id") |
| 407 | return |
| 408 | } |
| 409 | var idSlice []string |
| 410 | for _, v := range id { |
| 411 | idSlice = append(idSlice, strconv.Itoa(v)) |
| 412 | } |
| 413 | if sql, err = LeftJoinSqlBuild(tables, on, fields, 1, listRows, nil, nil, fmt.Sprintf("i.Status>=0 and i.Id in(%v)", strings.Join(idSlice, ","))); err == nil { |
| 414 | if num, err = orm.NewOrm().Raw(sql).Values(¶ms); num > 0 { |
| 415 | for _, param := range params { |
| 416 | es = append(es, ElasticSearchData{ |
| 417 | Id: helper.Interface2Int(param["Id"]), |
| 418 | Title: param["Title"].(string), |
| 419 | Keywords: param["Keywords"].(string), |
| 420 | Description: param["Description"].(string), |
| 421 | Vcnt: helper.Interface2Int(param["Vcnt"]), |
| 422 | Ccnt: helper.Interface2Int(param["Ccnt"]), |
| 423 | Dcnt: helper.Interface2Int(param["Dcnt"]), |
| 424 | Score: helper.Interface2Int(param["Score"]), |
| 425 | Size: helper.Interface2Int(param["Size"]), |
| 426 | Page: helper.Interface2Int(param["Page"]), |
| 427 | DocType: helper.Interface2Int(param["DocType"]), |
| 428 | DsId: helper.Interface2Int(param["DsId"]), |
| 429 | Price: helper.Interface2Int(param["Price"]), |
| 430 | TimeCreate: helper.Interface2Int(param["TimeCreate"]), |
| 431 | }) |
| 432 | } |
| 433 | } |
| 434 | } |
| 435 | return |
| 436 | } |
| 437 | |
| 438 | //查询需要索引的稳定id |
| 439 | //@param page 页面 |
no test coverage detected