Esempio n. 1
0
func (q *BasicQuery) SearchIndex(idxName string) (map[string]*indexer.IdxDoc, error) {
	notop := false
	if (q.term.mod == OpUnaryNot) || (q.term.mod == OpUnaryPro) {
		notop = true
	}
	if q.field == "" {
		res, err := indexer.SearchText(idxName, string(q.term.term), notop)
		return res, err
	}
	searchTerm := fmt.Sprintf("%s:%s", q.field, q.term.term)
	res, err := indexer.SearchIndex(idxName, searchTerm, notop)

	return res, err
}
Esempio n. 2
0
func (q *GroupedQuery) SearchIndex(idxName string) (map[string]*indexer.IdxDoc, error) {
	tmpRes := make([]groupQueryHolder, len(q.terms))
	for i, v := range q.terms {
		tmpRes[i].op = v.mod
		notop := false
		if v.mod == OpUnaryNot || v.mod == OpUnaryPro {
			notop = true
		}
		searchTerm := fmt.Sprintf("%s:%s", q.field, v.term)
		r, err := indexer.SearchIndex(idxName, searchTerm, notop)
		if err != nil {
			return nil, err
		}
		tmpRes[i].res = r
	}
	reqOp := false
	res := make(map[string]*indexer.IdxDoc)
	var req map[string]*indexer.IdxDoc

	// Merge the results, taking into account any + operators lurking about
	for _, t := range tmpRes {
		if t.op == OpUnaryReq {
			reqOp = true
			if req == nil {
				req = t.res
			} else {
				for k := range req {
					if _, found := t.res[k]; !found {
						delete(req, k)
					}
				}
			}
		} else if !reqOp {
			for k, v := range t.res {
				res[k] = v
			}
		}
	}
	if reqOp {
		req = res
	}
	return res, nil
}