lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [08/15] lucy git commit: Test Go bindings for SortCache.
Date Sat, 07 Nov 2015 02:48:57 GMT
Test Go bindings for SortCache.


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

Branch: refs/heads/master
Commit: 5cbd112fff62c7b3f165003a898eb4ac252297f2
Parents: 54733ad
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Sat Oct 31 18:25:30 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sun Nov 1 10:00:35 2015 -0800

----------------------------------------------------------------------
 go/lucy/index_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/5cbd112f/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index bf7fd67..842ec2e 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -384,3 +384,47 @@ func TestSnapshotMisc(t *testing.T) {
 		t.Errorf("SetPath/GetPath: %v", path)
 	}
 }
+
+func TestSortCacheMisc(t *testing.T) {
+	schema := NewSchema()
+	spec := NewFullTextType(NewStandardTokenizer())
+	spec.SetSortable(true)
+	schema.SpecField("content", spec)
+	folder := NewRAMFolder("")
+	indexer, _ := OpenIndexer(&OpenIndexerArgs{Index: folder, Schema: schema, Create: true})
+	indexer.AddDoc(&testDoc{Content: "foo"})
+	indexer.AddDoc(&testDoc{Content: "bar"})
+	indexer.AddDoc(&testDoc{Content: "baz"})
+	indexer.AddDoc(make(map[string]interface{}))
+	indexer.Commit()
+
+	searcher, _ := OpenIndexSearcher(folder)
+	segReaders := searcher.GetReader().SegReaders()
+	sortReader := segReaders[0].(SegReader).Obtain("Lucy::Index::SortReader").(SortReader)
+	sortCache := sortReader.FetchSortCache("content")
+
+	if card := sortCache.GetCardinality(); card != 4 {
+		t.Errorf("GetCardinality: %d", card)
+	}
+	if width := sortCache.GetOrdWidth(); width != 2 {
+		t.Errorf("GetOrdWidth: %d", width)
+	}
+
+	if lowest, ok := sortCache.Value(0).(string); !ok || lowest != "bar" {
+		t.Errorf("Ord")
+	}
+	if ord := sortCache.Ordinal(1); ord != 2 { // "foo" is ordinal 2
+		t.Errorf("Ordinal: %d", ord)
+	}
+	if nullOrd := sortCache.GetNullOrd(); nullOrd != 3 {
+		t.Errorf("GetNullOrd: %d", nullOrd)
+	}
+
+	if ord := sortCache.Find("foo"); ord != 2 {
+		t.Errorf("Find: %d", ord)
+	}
+
+	if sortCache.GetNativeOrds() {
+		t.Errorf("recent index shouldn't have native ords")
+	}
+}


Mime
View raw message