func init() { inMemStore, _ := inmem.Open() twoDocIndex = upside_down.NewUpsideDownCouch(inMemStore) for _, doc := range twoDocIndexDocs { twoDocIndex.Update(doc) } }
func init() { inMemStore, _ := inmem.Open() analysisQueue := upside_down.NewAnalysisQueue(1) twoDocIndex = upside_down.NewUpsideDownCouch(inMemStore, analysisQueue) for _, doc := range twoDocIndexDocs { twoDocIndex.Update(doc) } }
func BenchmarkInMemIndexing4Workers100Batch(b *testing.B) { s, err := inmem.Open() if err != nil { b.Fatal(err) } defer s.Close() CommonBenchmarkIndexBatch(b, s, 4, 100) }
func BenchmarkInMemIndexing2Workers(b *testing.B) { s, err := inmem.Open() if err != nil { b.Fatal(err) } defer s.Close() CommonBenchmarkIndex(b, s, 2) }
func TestTermSearcher(t *testing.T) { var queryTerm = "beer" var queryField = "desc" var queryBoost = 3.0 var queryExplain = true inMemStore, _ := inmem.Open() i := upside_down.NewUpsideDownCouch(inMemStore) i.Update(&document.Document{ ID: "a", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "b", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "c", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "d", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "e", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "f", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "g", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "h", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "i", Fields: []document.Field{ document.NewTextField("desc", []uint64{}, []byte("beer")), }, }) i.Update(&document.Document{ ID: "j", Fields: []document.Field{ document.NewTextField("title", []uint64{}, []byte("cat")), }, }) indexReader := i.Reader() defer indexReader.Close() searcher, err := NewTermSearcher(indexReader, queryTerm, queryField, queryBoost, queryExplain) if err != nil { t.Fatal(err) } defer searcher.Close() searcher.SetQueryNorm(2.0) idf := 1.0 + math.Log(float64(i.DocCount())/float64(searcher.Count()+1.0)) expectedQueryWeight := 3 * idf * 3 * idf if expectedQueryWeight != searcher.Weight() { t.Errorf("expected weight %v got %v", expectedQueryWeight, searcher.Weight()) } if searcher.Count() != 9 { t.Errorf("expected count of 9, got %d", searcher.Count()) } docMatch, err := searcher.Next() if err != nil { t.Errorf("expected result, got %v", err) } if docMatch.ID != "a" { t.Errorf("expected result ID to be 'a', got '%s", docMatch.ID) } docMatch, err = searcher.Advance("c") if err != nil { t.Errorf("expected result, got %v", err) } if docMatch.ID != "c" { t.Errorf("expected result ID to be 'c' got '%s'", docMatch.ID) } // try advancing past end docMatch, err = searcher.Advance("z") if err != nil { t.Fatal(err) } if docMatch != nil { t.Errorf("expected nil, got %v", docMatch) } // try pushing next past end docMatch, err = searcher.Next() if err != nil { t.Fatal(err) } if docMatch != nil { t.Errorf("expected nil, got %v", docMatch) } }