Esempio n. 1
0
func RunOrFilter(e search.Engine, t *testing.T) {
	q := e.NewQuery("Galaxy").Order("-pos")
	q.NewOrFilter().AddRegex("name", ".*galaxy.*").
		AddRegex("name", ".*ngc.*").AddExact("name", "m81")
	docs, err := q.Run()
	if err != nil {
		t.Fatalf("While running query: %v", err)
		return
	}
	if len(docs) != 6 {
		t.Errorf("Number of docs should be %v. Found: %v\n", len(soln), len(docs))
	} else {
		for idx, doc := range docs {
			m := doc.Data.(map[string]interface{})
			val, found := m["name"]
			if !found {
				t.Error("Should find name")
			} else {
				if val.(string) != soln[idx] {
					t.Errorf("Expected: %v. Found: %v\n", soln[idx], val.(string))
				}
			}
		}
	}
}
Esempio n. 2
0
func RunCount(e search.Engine, t *testing.T) {
	q := e.NewQuery("Galaxy").Order("-pos")
	q.NewOrFilter().AddRegex("name", ".*galaxy.*").
		AddRegex("name", ".*ngc.*").AddExact("name", "m81")
	count, err := q.Count()
	if err != nil {
		t.Fatalf("While running query: %v", err)
		return
	}
	if count != 6 {
		t.Errorf("Count of results should be %v. Found: %v\n", len(soln), count)
	}
}
Esempio n. 3
0
func RunFromLimit(e search.Engine, t *testing.T) {
	q := e.NewQuery("Galaxy").Order("-pos").From(2).Limit(2)
	q.NewOrFilter().AddRegex("name", ".*galaxy.*").
		AddRegex("name", ".*ngc.*").AddExact("name", "m81")
	docs, err := q.Run()
	if err != nil {
		t.Fatalf("While running query: %v", err)
		return
	}
	if len(docs) != 2 {
		t.Errorf("Number of docs should be %v. Found: %v\n", 2, len(docs))
	}
	check(docs[0], "galaxy ngc 1512", t)
	check(docs[1], "ngc 123", t)
}
Esempio n. 4
0
func RunAndFilter(e search.Engine, t *testing.T) {
	q := e.NewQuery("Galaxy")
	q.NewAndFilter().AddExact("name", "2masx").AddRegex("name", ".*ma.*")
	docs, err := q.Run()
	if err != nil {
		t.Fatalf("While running query: %v", err)
		return
	}
	if len(docs) != 1 {
		t.Errorf("Number of docs should be 1. Found: %v\n", len(docs))
	} else {
		d := docs[0]
		m := d.Data.(map[string]interface{})
		val, found := m["name"]
		if !found {
			t.Error("Should find name")
		} else {
			if val.(string) != "2masx" {
				t.Errorf("Expected 2masx. Found: %v\n", val.(string))
			}
		}
	}
}