根据id查询搜索结果
(id []int, withoutCont ...bool)
| 126 | |
| 127 | // 根据id查询搜索结果 |
| 128 | func (m *DocumentSearchResult) GetDocsById(id []int, withoutCont ...bool) (docs []DocResult, err error) { |
| 129 | if len(id) == 0 { |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | var idArr []string |
| 134 | for _, i := range id { |
| 135 | idArr = append(idArr, fmt.Sprint(i)) |
| 136 | } |
| 137 | |
| 138 | fields := []string{ |
| 139 | "d.document_id", "d.document_name", "d.identify", "d.vcnt", "d.create_time", "b.book_id", |
| 140 | } |
| 141 | |
| 142 | // 不返回内容 |
| 143 | if len(withoutCont) == 0 || !withoutCont[0] { |
| 144 | fields = append(fields, "b.identify book_identify", "d.release", "b.book_name") |
| 145 | } |
| 146 | |
| 147 | sqlFmt := "select " + strings.Join(fields, ",") + " from md_documents d left join md_books b on d.book_id=b.book_id where d.document_id in(%v)" |
| 148 | sql := fmt.Sprintf(sqlFmt, strings.Join(idArr, ",")) |
| 149 | |
| 150 | var rows []DocResult |
| 151 | var cnt int64 |
| 152 | |
| 153 | cnt, err = orm.NewOrm().Raw(sql).QueryRows(&rows) |
| 154 | if cnt > 0 { |
| 155 | docMap := make(map[int]DocResult) |
| 156 | for _, row := range rows { |
| 157 | docMap[row.DocumentId] = row |
| 158 | } |
| 159 | client := NewElasticSearchClient() |
| 160 | for _, i := range id { |
| 161 | if doc, ok := docMap[i]; ok { |
| 162 | doc.Release = client.html2Text(doc.Release) |
| 163 | docs = append(docs, doc) |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | return |
| 169 | } |