lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [11/14] lucy git commit: Test IndexSearcher Go bindings.
Date Mon, 28 Sep 2015 19:52:27 GMT
Test IndexSearcher Go bindings.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/faab39e0
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/faab39e0
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/faab39e0

Branch: refs/heads/master
Commit: faab39e04c989d96b4e5fc6b069863e4ce06cb0d
Parents: 63fd5b8
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Sep 15 13:34:34 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Sep 15 15:54:51 2015 -0700

----------------------------------------------------------------------
 go/lucy/search_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/faab39e0/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index d084f53..00d68c1 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -567,3 +567,58 @@ func TestSortCollectorBasics(t *testing.T) {
 		t.Errorf("Weird MatchDoc: %d", docID)
 	}
 }
+
+func TestIndexSearcherMisc(t *testing.T) {
+	index := createTestIndex("a", "b", "c", "a a")
+	searcher, _ := OpenIndexSearcher(index)
+	if got := searcher.DocFreq("content", "a"); got != 2 {
+		t.Errorf("DocFreq expected 2, got %d", got)
+	}
+	if got := searcher.DocMax(); got != 4 {
+		t.Errorf("DocMax expected 4, got %d", got)
+	}
+	if _, ok := searcher.GetReader().(PolyReader); !ok {
+		t.Error("GetReader")
+	}
+	if _, ok := searcher.FetchDocVec(4).(DocVector); !ok {
+		t.Error("DocVector")
+	}
+}
+
+func TestIndexSearcherOpenClose(t *testing.T) {
+	if _, err := OpenIndexSearcher(NewRAMFolder("")); err == nil {
+		t.Error("Open non-existent index")
+	}
+	if _, err := OpenIndexSearcher(42); err == nil {
+		t.Error("Garbage 'index' argument")
+	}
+	index := createTestIndex("a", "b", "c")
+	searcher, _ := OpenIndexSearcher(index)
+	searcher.Close()
+}
+
+func TestIndexSearcherHits(t *testing.T) {
+	index := createTestIndex("a", "b", "c", "a a")
+	searcher, _ := OpenIndexSearcher(index)
+	if got, _ := searcher.Hits("a", 0, 1, nil); got.TotalHits() != 2 {
+		t.Errorf("Hits() with query string: %d", got.TotalHits())
+	}
+	termQuery := NewTermQuery("content", "a")
+	if got, _ := searcher.Hits(termQuery, 0, 1, nil); got.TotalHits() != 2 {
+		t.Errorf("Hits() with TermQuery object: %d", got.TotalHits())
+	}
+
+	if _, err := searcher.Hits(42, 0, 1, nil); err == nil {
+		t.Error("Garbage 'query' argument")
+	}
+}
+
+func TestIndexSearcherTopDocs(t *testing.T) {
+	index := createTestIndex("a", "b")
+	searcher, _ := OpenIndexSearcher(index)
+	topDocs := searcher.TopDocs(NewTermQuery("content", "b"), 10, nil)
+	matchDocs := topDocs.GetMatchDocs()
+	if docID := matchDocs[0].GetDocID(); docID != 2 {
+		t.Errorf("TopDocs expected 2, got %d", docID)
+	}
+}


Mime
View raw message