示例#1
0
func (this *IndexSet) SearchByRules(rules /*map[string]interface{}*/ []SearchRule) ([]utils.DocIdInfo, bool) {
	functime := utils.InitTime()
	fmt.Printf("SearchByRules: %v \n", functime("Start"))
	var res []utils.DocIdInfo
	for index, rule := range rules {
		var sub_res []utils.DocIdInfo
		var ok bool
		if rule.Field == "query" {
			sub_res, ok = this.Search(rule.Query)
		} else {
			//this.Logger.Info(" Field : %v Query : %v",rule.Field, rule.Query)
			fmt.Printf("SearchByRules: %v \n", functime("Start SearchField"))
			sub_res, ok = this.SearchField(rule.Query, rule.Field)
			fmt.Printf("SearchByRules: %v \n", functime("End SearchField"))
		}
		if !ok {
			return nil, false
		}
		if index == 0 {
			res = sub_res
		} else {
			fmt.Printf("SearchByRules: %v \n", functime("Start Interaction"))
			res, ok = utils.Interaction(res, sub_res)
			fmt.Printf("SearchByRules: %v \n", functime("End Interaction"))
			if !ok {
				return nil, false
			}
		}
		//this.Logger.Info(" RES :: %v ", res)
	}

	//BitMap过滤失效的doc_id
	//this.Logger.Info(" %v ",res)
	fmt.Printf("SearchByRules: %v \n", functime("Start Bitmap"))
	r := make([]utils.DocIdInfo, len(res))
	r_index := 0
	for i, _ := range res {
		//this.Logger.Info(" %v ",res[i].DocId)
		if this.BitMap.GetBit(uint64(res[i].DocId)) == 0 {
			r[r_index] = res[i]
			r_index++
			//r = append(r,res[i])
		}
	}
	fmt.Printf("SearchByRules: %v \n", functime("End Bitmap"))

	//TODO 自定义过滤
	fmt.Printf("SearchByRules: %v \n", functime("End SearchByRules"))
	return r[:r_index], true
}
示例#2
0
/*****************************************************************************
*  function name : SearchFieldByNumber
*  params : query field
*  return :
*
*  description : 在指定字段检索数字
*
******************************************************************************/
func (this *IndexSet) SearchFieldByNumber(query int64, field string) ([]utils.DocIdInfo, bool) {
	functime := utils.InitTime()
	fmt.Printf("SearchFieldByNumber: %v \n", functime("Start"))
	_, ok := this.IvtIndex[field]
	if !ok {
		return nil, false
	}

	l, ok := this.IvtIndex[field].Find(query)
	if !ok {
		return nil, false
	}
	//this.Logger.Info("[Number : %v ] [Field: %v ] DocIDs : %v", query, field, l)
	fmt.Printf("SearchFieldByNumber: %v \n", functime("Find"))
	return l, true
}
示例#3
0
//路由设置
//数据分发
func (this *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	
	var err error
	var body []byte
	var startTime, endTime time.Time

	startTime = time.Now()
	functime := utils.InitTime()
	result := make(map[string]interface{})
	
	header := w.Header()
	header.Add("Content-Type", "application/json")
	header.Add("charset", "UTF-8")
	
	//生成log_id
	rand := rand.New(rand.NewSource(time.Now().UnixNano()))
	log_id1 := rand.Intn(100000)
	log_id2 := rand.Intn(100000)
	log_id := fmt.Sprintf("%d-%d", log_id1, log_id2)
	

	stype,err := this.ParseURL(r.RequestURI)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		io.WriteString(w, MakeErrorResult(-1, err.Error()))
	} else {
		RequestParams, err := this.parseArgs(r)
		if err != nil {
			result["error_code"] = -1
			result["message"] = "解析参数错误" //err.Error()
			goto END
		}

		body, err = ioutil.ReadAll(r.Body)
		if err != nil && err != io.EOF {
			result["error_code"] = -1
			result["message"] = "读取请求数据出错,请重新提交" //err.Error()
			goto END
		}
		//处理业务逻辑
		if stype == 1 { //搜索
			err := this.Processors["search"].Process(log_id,body,RequestParams,result,functime)
			if err !=nil{
				goto END
			}
		}
		
		if stype == 2 { //数据更新
			err := this.Processors["update"].Process(log_id,body,RequestParams,result,functime)
			if err !=nil{
				goto END
			}
		}
		
		if stype == 3 { //监控,控制
			
		}
		
	}

END:
	if err != nil {
		this.Logger.Error("[LOG_ID:%v] %v", log_id, err)
	}

	endTime = time.Now()
	result["cost"] = fmt.Sprintf("%v", endTime.Sub(startTime))
	result["request_url"] = r.RequestURI
	this.Logger.Info("[LOG_ID:%v] [COST:%v]", log_id, result["cost"])
	resStr, _ := this.createJSON(result)
	io.WriteString(w, resStr)
	return 
}