Example #1
0
func getMatches() []string {
	q := query.New()
	ft := q.NewFilter(filtFn)
	q.SetRoots(ft)

	q.Open()
	defer q.Close()

	batchN := 1000
	timeout := time.After(10 * time.Second)
	for skip, done := 0, false; !done; skip += batchN {
		blobs, err := cl.BlobsBackward(time.Now(), batchN, skip)
		if len(blobs) > 0 {
			q.Process(blobs...)
		}
		if *max > 0 && len(q.Results) == *max {
			break
		}

		if err != nil {
			break
		}
		select {
		case <-timeout:
			done = true
		default:
		}
	}
	if *max > 0 {
		q.Results = q.Results[:*max]
	}
	return blob.RefsFor(q.Results)
}
Example #2
0
func testQuery() {
	b1 := blob.NewRaw([]byte("I am not json"))
	b2 := blob.NewRaw([]byte("{\"key\":\"I am wrong json\"}"))
	b3 := blob.NewRaw([]byte("{\"key\":\"I am right json\"}"))

	q := query.New()

	isjson := q.NewFilter(query.IsJson)
	right := q.NewFilter(query.Contains("right"))

	isjson.SendTo(right)
	q.SetRoots(isjson)

	q.Open()
	defer q.Close()

	q.Process(b1, b2, b3)

	fmt.Println("results: ", q.Results)
}