lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [11/15] lucy git commit: Tune and test Go bindings for Segment.
Date Sat, 07 Nov 2015 02:49:00 GMT
Tune and test Go bindings for Segment.


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

Branch: refs/heads/master
Commit: c8df9f639b10cf4687669daaf8e1628268b89698
Parents: 5cbd112
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Sat Oct 31 21:01:24 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sun Nov 1 10:00:35 2015 -0800

----------------------------------------------------------------------
 go/build.go           |  5 ++++
 go/lucy/index.go      | 17 ++++++++++++++
 go/lucy/index_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/c8df9f63/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 3b0a95d..6060f5b 100644
--- a/go/build.go
+++ b/go/build.go
@@ -183,6 +183,11 @@ func specClasses(parcel *cfc.Parcel) {
 	snapshotBinding.SpecMethod("Write_File", "WriteFile(Folder, string) error")
 	snapshotBinding.Register()
 
+	segBinding := cfc.NewGoClass(parcel, "Lucy::Index::Segment")
+	segBinding.SpecMethod("Read_File", "ReadFile(Folder) error")
+	segBinding.SpecMethod("Write_File", "WriteFile(Folder) error")
+	segBinding.Register()
+
 	schemaBinding := cfc.NewGoClass(parcel, "Lucy::Plan::Schema")
 	schemaBinding.SpecMethod("All_Fields", "AllFields() []string")
 	schemaBinding.Register()

http://git-wip-us.apache.org/repos/asf/lucy/blob/c8df9f63/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index 18a9992..f186f7d 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -21,6 +21,7 @@ package lucy
 #include "Lucy/Index/IndexManager.h"
 #include "Lucy/Index/BackgroundMerger.h"
 #include "Lucy/Index/TermVector.h"
+#include "Lucy/Index/Segment.h"
 #include "Lucy/Index/Snapshot.h"
 #include "Lucy/Document/Doc.h"
 #include "Lucy/Plan/Schema.h"
@@ -367,3 +368,19 @@ func (s *SnapshotIMP) WriteFile(folder Folder, path string) error {
 		C.LUCY_Snapshot_Write_File(self, folderC, pathC)
 	})
 }
+
+func (s *SegmentIMP) WriteFile(folder Folder) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Segment)(clownfish.Unwrap(s, "s"))
+		folderC := (*C.lucy_Folder)(clownfish.Unwrap(folder, "folder"))
+		C.LUCY_Seg_Write_File(self, folderC)
+	})
+}
+
+func (s *SegmentIMP) ReadFile(folder Folder) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Segment)(clownfish.Unwrap(s, "s"))
+		folderC := (*C.lucy_Folder)(clownfish.Unwrap(folder, "folder"))
+		C.LUCY_Seg_Read_File(self, folderC)
+	})
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/c8df9f63/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index 842ec2e..d60e59b 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -428,3 +428,60 @@ func TestSortCacheMisc(t *testing.T) {
 		t.Errorf("recent index shouldn't have native ords")
 	}
 }
+
+func TestSegmentMisc(t *testing.T) {
+	var err error
+
+	seg := NewSegment(4)
+	if name := seg.GetName(); name != "seg_4" {
+		t.Errorf("GetName: %s", name)
+	}
+	if num := seg.GetNumber(); num != 4 {
+		t.Errorf("GetNumber: %d", num)
+	}
+
+	if num := seg.AddField("field1"); num != 1 {
+		t.Errorf("AddField: %d", num)
+	}
+	if field := seg.FieldName(1); field != "field1" {
+		t.Errorf("FieldName: %v", field)
+	}
+	if num := seg.FieldNum("field1"); num != 1 {
+		t.Errorf("FieldNum: %d", num)
+	}
+
+	metadata := map[string]interface{}{
+		"foo": "1",
+		"bar": "2",
+	}
+	seg.StoreMetadata("mycomponent", metadata)
+	if got := seg.FetchMetadata("mycomponent"); !reflect.DeepEqual(got, metadata) {
+		t.Errorf("Store/FetchMetadata: %v", got)
+	}
+	if got := seg.GetMetadata(); got["mycomponent"] == nil {
+		t.Errorf("%v", got)
+	}
+
+	seg.SetCount(42)
+	seg.IncrementCount(5)
+	if got := seg.GetCount(); got != 47 {
+		t.Errorf("SetCount/GetCount: %d", got)
+	}
+
+	folder := NewRAMFolder("")
+	folder.MkDir("seg_4")
+	err = seg.WriteFile(folder)
+	if err != nil {
+		t.Errorf("WriteFile: %v", err)
+	}
+	dupe := NewSegment(4)
+	dupe.ReadFile(folder)
+	if err != nil {
+		t.Errorf("WriteFile: %v", err)
+	}
+
+	other := NewSegment(5)
+	if got := seg.CompareTo(other); got >= 0 {
+		t.Errorf("CompareTo (seg 4 vs seg 5): %d", got)
+	}
+}


Mime
View raw message