func (self *RankTask) PVRank() { log.Println("start pv rank") nobj := models.NewBaseModel() if novels, err := nobj.GetAllNovel(); err != nil { log.Println(err.Error()) } else { //根据pv排序 novelspv := models.NovelsPv(novels) models.NovelPvSort(novelspv) npv := []*models.Novel(novelspv) now := time.Now() o := orm.NewOrm() //插入pv排行榜 pvrank := []models.Clickrank{} for _, novel := range npv { pvrank = append(pvrank, models.Clickrank{ Novelid: novel.Id, Firstid: novel.Firstid, Secondid: novel.Secondid, Novelpv: novel.Novelpv, Novelcollect: novel.Novelcollect, Createtime: now, }) } if _, err := o.InsertMulti(1, pvrank); err != nil { log.Println("insert pv rank:", err.Error()) } else { log.Println("insert pv rank success") } } }
func (self *RankTask) CollectRank() { log.Println("start collect rank") nobj := models.NewBaseModel() if novels, err := nobj.GetAllNovel(); err != nil { log.Println(err.Error()) } else { //根据collect排序 novelscollect := models.NovelsCollect(novels) models.NovelCollectSort(novelscollect) nco := []*models.Novel(novelscollect) now := time.Now() o := orm.NewOrm() //插入collect排行榜 collectrank := []models.Collectrank{} for _, novel := range nco { collectrank = append(collectrank, models.Collectrank{ Novelid: novel.Id, Firstid: novel.Firstid, Secondid: novel.Secondid, Novelpv: novel.Novelpv, Novelcollect: novel.Novelcollect, Createtime: now, }) } if _, err := o.InsertMulti(1, collectrank); err != nil { log.Println("insert collect rank:", err.Error()) } else { log.Println("insert collect rank success") } } }
func (self *IndexTask) Index() { doindex := func(docid uint64, arg string) { self.searcher.IndexDocument(docid, search.DocumentIndexData{ Content: arg, }) } //生成一个管理中心 mc := NewManagementCenter(100, 100) go mc.Start() //每天更新一次 for { novels, err := models.NewBaseModel().GetAllNovelForIndex() if err != nil { log.Println(err.Error()) } else { for _, novel := range novels { mc.AddTask(&Task{ Execut: doindex, Arg: novel.Title + novel.Author, Docid: uint64(novel.Id), }) } } time.Sleep(86400) } }
func (self *NovelSearchHandler) Handle(w http.ResponseWriter, r *http.Request, web *utils.Web, text string) { searcher := web.Searcher searchresult := searcher.Search(search.SearchRequest{ Text: text, RankOptions: &search.RankOptions{ SearchScorer: scorer.NewBM25Scorer(), }, }) //获取docid列表 var docids []int for _, doc := range searchresult.Docs { docids = append(docids, int(doc.DocId)) } picpath := web.Settings["NOVELPIC"] res, err := models.NewBaseModel().GetNovels(docids, picpath) if err != nil { self.JsonResponse(w, "", 200) } else { self.JsonResponse(w, res, 200) } }