Ejemplo n.º 1
0
func (self *SearchHandler) Handle(w http.ResponseWriter, r *http.Request, g kernel.G, sr SearchRequest) {
	searcher, _ := g.DIY["searcher"].(search.Engine)
	self.JsonResponse(w, searcher.Search(search.SearchRequest{
		Text:    sr.Text,
		Labels:  sr.Labels,
		DocIds:  sr.DocIds,
		Timeout: sr.TimeOut,
		RankOptions: &search.RankOptions{
			SearchScorer: scorer.NewBM25Scorer(),
		},
	}), 200)
}
Ejemplo n.º 2
0
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)
	}
}