lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [07/13] lucy git commit: Add error retval for SortCache Go bindings.
Date Tue, 24 Nov 2015 23:38:29 GMT
Add error retval for SortCache Go bindings.

Some methods need to trap exceptions and return error objects.


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

Branch: refs/heads/master
Commit: 3d636a19d41e9f049aaa444db097de5e31895e9a
Parents: d483dd0
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Nov 12 19:11:48 2015 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Nov 20 16:43:37 2015 -0800

----------------------------------------------------------------------
 go/build.go           |  6 ++++++
 go/lucy/index.go      | 31 +++++++++++++++++++++++++++++++
 go/lucy/index_test.go | 15 +++++++++------
 3 files changed, 46 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/3d636a19/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 2b94cc5..ccd606b 100644
--- a/go/build.go
+++ b/go/build.go
@@ -202,6 +202,12 @@ func specClasses(parcel *cfc.Parcel) {
 	segBinding.SpecMethod("Write_File", "WriteFile(Folder) error")
 	segBinding.Register()
 
+	sortCacheBinding := cfc.NewGoClass(parcel, "Lucy::Index::SortCache")
+	sortCacheBinding.SpecMethod("Value", "Value(int32) (interface{}, error)")
+	sortCacheBinding.SpecMethod("Ordinal", "Ordinal(int32) (int32, error)")
+	sortCacheBinding.SpecMethod("Find", "Find(interface{}) (int32, error)")
+	sortCacheBinding.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/3d636a19/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index f186f7d..230e050 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -23,6 +23,7 @@ package lucy
 #include "Lucy/Index/TermVector.h"
 #include "Lucy/Index/Segment.h"
 #include "Lucy/Index/Snapshot.h"
+#include "Lucy/Index/SortCache.h"
 #include "Lucy/Document/Doc.h"
 #include "Lucy/Plan/Schema.h"
 #include "Clownfish/Hash.h"
@@ -384,3 +385,33 @@ func (s *SegmentIMP) ReadFile(folder Folder) error {
 		C.LUCY_Seg_Read_File(self, folderC)
 	})
 }
+
+func (s *SortCacheIMP) Value(ord int32) (retval interface{}, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_SortCache)(clownfish.Unwrap(s, "s"))
+		retvalCF := C.LUCY_SortCache_Value(self, C.int32_t(ord))
+		defer C.cfish_decref(unsafe.Pointer(retvalCF))
+		retval = clownfish.ToGo(unsafe.Pointer(retvalCF))
+	})
+	return retval, err
+}
+
+func (s *SortCacheIMP) Ordinal(docId int32) (retval int32, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_SortCache)(clownfish.Unwrap(s, "s"))
+		retvalCF := C.LUCY_SortCache_Ordinal(self, C.int32_t(docId))
+		retval = int32(retvalCF)
+	})
+	return retval, err
+}
+
+func (s *SortCacheIMP) Find(term interface{}) (retval int32, err error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_SortCache)(clownfish.Unwrap(s, "s"))
+		termCF := (*C.cfish_Obj)(clownfish.GoToClownfish(term, unsafe.Pointer(C.CFISH_OBJ), true))
+		defer C.cfish_decref(unsafe.Pointer(termCF))
+		retvalCF := C.LUCY_SortCache_Find(self, termCF)
+		retval = int32(retvalCF)
+	})
+	return retval, err
+}

http://git-wip-us.apache.org/repos/asf/lucy/blob/3d636a19/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index 5fb4d8b..e7c93a9 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -386,6 +386,8 @@ func TestSnapshotMisc(t *testing.T) {
 }
 
 func TestSortCacheMisc(t *testing.T) {
+	var err error
+
 	schema := NewSchema()
 	spec := NewFullTextType(NewStandardTokenizer())
 	spec.SetSortable(true)
@@ -410,18 +412,19 @@ func TestSortCacheMisc(t *testing.T) {
 		t.Errorf("GetOrdWidth: %d", width)
 	}
 
-	if lowest, ok := sortCache.Value(0).(string); !ok || lowest != "bar" {
-		t.Errorf("Ord")
+	lowest, err := sortCache.Value(0)
+	if _, ok := lowest.(string); err != nil || !ok || lowest != "bar" {
+		t.Errorf("Value: %v", err)
 	}
-	if ord := sortCache.Ordinal(1); ord != 2 { // "foo" is ordinal 2
-		t.Errorf("Ordinal: %d", ord)
+	if ord, err := sortCache.Ordinal(1); err != nil || ord != 2 { // "foo" is ordinal 2
+		t.Errorf("Ordinal: %d, %v", ord, err)
 	}
 	if nullOrd := sortCache.GetNullOrd(); nullOrd != 3 {
 		t.Errorf("GetNullOrd: %d", nullOrd)
 	}
 
-	if ord := sortCache.Find("foo"); ord != 2 {
-		t.Errorf("Find: %d", ord)
+	if ord, err := sortCache.Find("foo"); err != nil || ord != 2 {
+		t.Errorf("Find: %d, %v", ord, err)
 	}
 
 	if sortCache.getNativeOrds() {


Mime
View raw message