Exemple #1
0
/*
Return resulting keys from a scan.
*/
func (db *Database) Keys(s *bitvec.Iterator) chan string {
	ch := make(chan string)
	go func() {
		for id := range s.Ids() {
			ch <- db.keys[id]
		}
		close(ch)
	}()
	return ch
}
Exemple #2
0
func buildQuery(ctx *Context, x interface{}) *bitvec.Iterator {
	var query *bitvec.Iterator
	switch v := x.(type) {
	case string:
		query = ctx.db.Query(v)
	case []interface{}:
		op := v[0].(string)
		query = buildQuery(ctx, v[1])
		if op == "not" {
			query = query.Not()
		} else {
			if op == "and" {
				for _, q := range v[2:] {
					query = query.And(buildQuery(ctx, q))
				}
			} else if op == "or" {
				for _, q := range v[2:] {
					query = query.Or(buildQuery(ctx, q))
				}
			} else if op == "xor" {
				for _, q := range v[2:] {
					query = query.Xor(buildQuery(ctx, q))
				}
			}
		}
	}
	return query
}