MCPcopy Index your code
hub / github.com/TruthHun/BookStack / GetDocsById

Method GetDocsById

models/document_search_result.go:128–169  ·  view source on GitHub ↗

根据id查询搜索结果

(id []int, withoutCont ...bool)

Source from the content-addressed store, hash-verified

126
127// 根据id查询搜索结果
128func (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}

Callers 3

SearchMethod · 0.80
ResultMethod · 0.80
SearchDocMethod · 0.80

Calls 3

html2TextMethod · 0.95
NewElasticSearchClientFunction · 0.85
appendFunction · 0.50

Tested by

no test coverage detected