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

Function SearchByMysql

models/Models.go:295–371  ·  view source on GitHub ↗

使用MySQL的like查询 @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 int)

Source from the content-addressed store, hash-verified

293//@param p 页码
294//@param listRows 每页显示记录数
295func SearchByMysql(wd, sourceType, order string, p, listRows int) (data []orm.Params, total int64) {
296 tables := []string{GetTableDocumentInfo() + " i", GetTableDocument() + " d", GetTableDocumentStore() + " ds"}
297 on := []map[string]string{
298 {"i.Id": "d.Id"},
299 {"i.DsId": "ds.Id"},
300 }
301 fields := map[string][]string{
302 "i": {"Score", "TimeCreate", "Id", "Dcnt", "Vcnt", "Price"},
303 "d": {"Title", "Description"},
304 "ds": {"Page", "Size", "ExtCate", "Md5"},
305 }
306 //排序
307 orderBy := []string{}
308 switch strings.ToLower(order) {
309 case "new":
310 orderBy = []string{"i.Id desc"}
311 case "down":
312 orderBy = []string{"i.Dcnt desc"}
313 case "page":
314 orderBy = []string{"ds.Page desc"}
315 case "score":
316 orderBy = []string{"i.Score desc"}
317 case "size":
318 orderBy = []string{"ds.Size desc"}
319 case "collect":
320 orderBy = []string{"i.Ccnt desc"}
321 case "view":
322 orderBy = []string{"i.Vcnt desc"}
323 }
324 cond := " i.Status>=0 and d.Title like ? "
325 //文档类型过滤条件
326 ExtNum := 0 //这些也暂时写死了,后面再优化....
327 switch strings.ToLower(sourceType) {
328 case "doc":
329 ExtNum = helper.EXT_NUM_WORD
330 case "ppt":
331 ExtNum = helper.EXT_NUM_PPT
332 case "xls":
333 ExtNum = helper.EXT_NUM_EXCEL
334 case "pdf":
335 ExtNum = helper.EXT_NUM_PDF
336 case "txt":
337 ExtNum = helper.EXT_NUM_TEXT
338 case "other":
339 ExtNum = helper.EXT_NUM_OTHER
340 }
341 if ExtNum > 0 {
342 cond = cond + " and ds.ExtNum=" + strconv.Itoa(ExtNum)
343 }
344 o := orm.NewOrm()
345 //数量统计
346 if sql, err := LeftJoinSqlBuild(tables, on, map[string][]string{"i": []string{"Count"}}, 1, 100000000, nil, nil, cond); err == nil {
347 sql = strings.Replace(sql, "i.Count", "count(d.Id) cnt", -1)
348 var params []orm.Params
349 o.Raw(sql, "%"+wd+"%").Values(&params)
350 if len(params) > 0 {
351 total, _ = strconv.ParseInt(params[0]["cnt"].(string), 10, 64)
352 }

Callers

nothing calls this directly

Calls 4

GetTableDocumentInfoFunction · 0.85
GetTableDocumentFunction · 0.85
GetTableDocumentStoreFunction · 0.85
LeftJoinSqlBuildFunction · 0.85

Tested by

no test coverage detected