lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [02/16] lucy git commit: Support Folder as arg for IndexSearcher, Indexer.
Date Fri, 11 Sep 2015 22:00:27 GMT
Support Folder as arg for IndexSearcher, Indexer.

OpenIndexer and OpenIndexSearcher should accept either a Go `string`
path or a Clownfish Folder as the `index` argument.


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

Branch: refs/heads/master
Commit: b69adb89aa9fc6a9c7d97c2729a9a0ceadc103be
Parents: c94acc5
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Aug 11 13:07:02 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Wed Sep 9 16:17:59 2015 -0700

----------------------------------------------------------------------
 go/lucy/index.go  | 22 +++++-----------------
 go/lucy/search.go | 10 ++--------
 2 files changed, 7 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b69adb89/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index a55771e..4aab0a2 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -47,20 +47,10 @@ type OpenIndexerArgs struct {
 }
 
 func OpenIndexer(args *OpenIndexerArgs) (obj Indexer, err error) {
-	var schemaC *C.lucy_Schema = nil
-	if args.Schema != nil {
-		schemaC = (*C.lucy_Schema)(unsafe.Pointer(args.Schema.TOPTR()))
-	}
-	switch args.Index.(type) {
-	case string:
-	default:
-		panic("TODO: support Folder")
-	}
-	ixLoc := clownfish.NewString(args.Index.(string))
-	var managerC *C.lucy_IndexManager = nil
-	if args.Manager != nil {
-		managerC = (*C.lucy_IndexManager)(unsafe.Pointer(args.Manager.TOPTR()))
-	}
+	schema := (*C.lucy_Schema)(clownfish.UnwrapNullable(args.Schema))
+	manager := (*C.lucy_IndexManager)(clownfish.UnwrapNullable(args.Manager))
+	index := (*C.cfish_Obj)(clownfish.GoToClownfish(args.Index, unsafe.Pointer(C.CFISH_OBJ),
false))
+	defer C.cfish_decref(unsafe.Pointer(index))
 	var flags int32
 	if args.Create {
 		flags = flags | int32(C.lucy_Indexer_CREATE)
@@ -69,9 +59,7 @@ func OpenIndexer(args *OpenIndexerArgs) (obj Indexer, err error) {
 		flags = flags | int32(C.lucy_Indexer_TRUNCATE)
 	}
 	err = clownfish.TrapErr(func() {
-		cfObj := C.lucy_Indexer_new(schemaC,
-			(*C.cfish_Obj)(unsafe.Pointer(ixLoc.TOPTR())),
-			managerC, C.int32_t(flags))
+		cfObj := C.lucy_Indexer_new(schema, index, manager, C.int32_t(flags))
 		obj = WRAPIndexer(unsafe.Pointer(cfObj))
 	})
 	return obj, err

http://git-wip-us.apache.org/repos/asf/lucy/blob/b69adb89/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index c71048b..3335252 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -40,14 +40,8 @@ type HitsIMP struct {
 }
 
 func OpenIndexSearcher(index interface{}) (obj IndexSearcher, err error) {
-	var indexC *C.cfish_Obj
-	switch index.(type) {
-	case string:
-		ixLoc := clownfish.NewString(index.(string))
-		indexC = (*C.cfish_Obj)(unsafe.Pointer(ixLoc.TOPTR()))
-	default:
-		panic("TODO: support Folder")
-	}
+	indexC := (*C.cfish_Obj)(clownfish.GoToClownfish(index, unsafe.Pointer(C.CFISH_OBJ), false))
+	defer C.cfish_decref(unsafe.Pointer(indexC))
 	err = clownfish.TrapErr(func() {
 		cfObj := C.lucy_IxSearcher_new(indexC)
 		obj = WRAPIndexSearcher(unsafe.Pointer(cfObj))


Mime
View raw message