MCPcopy Index your code
hub / github.com/TruthHun/DocHub / Search

Function Search

models/Models.go:261–287  ·  view source on GitHub ↗

资源搜索 @param wd 搜索关键字 @param sourceType 搜索的资源类型,可选择:doc、ppt、xls、pdf、txt、other、all @param order 排序,可选值:new(最新)、down(下载)、page(页数)、score(评分)、size(大小)、collect(收藏)、view(浏览)、default(默认) @param p 页码 @param listRows 每页显示记录数 @

(wd, sourceType, order string, p, listRows, accuracy int)

Source from the content-addressed store, hash-verified

259//@param listRows 每页显示记录数
260//@param accuracy 是否精确搜索
261func Search(wd, sourceType, order string, p, listRows, accuracy int) (res Result) {
262
263 //========== like 查询 ==============
264 //TODO:目前的查询没有排序、没有分类等,需要上elasticsearch
265
266 //SELECT * from hc_document d left JOIN hc_document_info i on d.Id=i.Id LEFT JOIN hc_document_store s on i.DsId=s.Id where d.Title LIKE '%js%' GROUP BY s.Id ORDER by i.Dcnt DESC
267 //fields := "" //查询的字段
268 start := time.Now().UnixNano()
269 res.Word = []string{wd}
270 res.Msg = "ok"
271 res.Status = 1
272 qs := orm.NewOrm().QueryTable(GetTableDocument()).Filter("Title__icontains", wd)
273 if res.Total, _ = qs.Count(); res.Total > 0 {
274 var (
275 docs []Document
276 ids []string
277 )
278 qs.Limit(listRows).Offset((p-1)*listRows).All(&docs, "Id")
279 for _, doc := range docs {
280 ids = append(ids, strconv.Itoa(doc.Id))
281 }
282 res.Ids = strings.Join(ids, ",")
283 }
284 end := time.Now().UnixNano()
285 res.Time = float64(end-start) / 1000000000
286 return
287}
288
289//使用MySQL的like查询
290//@param wd 搜索关键字

Callers

nothing calls this directly

Calls 3

GetTableDocumentFunction · 0.85
CountMethod · 0.80
AllMethod · 0.80

Tested by

no test coverage detected