lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [12/14] lucy git commit: Generalize `query` param in `Hits`.
Date Mon, 28 Sep 2015 19:52:28 GMT
Generalize `query` param in `Hits`.

Allow both Query objects and query strings.


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

Branch: refs/heads/master
Commit: 63fd5b8b89ba40cb51934fe087cd3d2c8e8ca3d8
Parents: 40a1eec
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Tue Sep 15 13:33:37 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Tue Sep 15 15:54:51 2015 -0700

----------------------------------------------------------------------
 go/lucy/search.go | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/63fd5b8b/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index b47b340..e18eee7 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -83,25 +83,17 @@ func doClose(obj Searcher) error {
 	})
 }
 
-func doHits(obj Searcher, query interface{}, offset uint32, numWanted uint32,
+func doHits(s Searcher, query interface{}, offset uint32, numWanted uint32,
 	sortSpec SortSpec) (hits Hits, err error) {
-	self := ((*C.lucy_Searcher)(unsafe.Pointer(obj.TOPTR())))
-	var sortSpecC *C.lucy_SortSpec
-	if sortSpec != nil {
-		sortSpecC = (*C.lucy_SortSpec)(unsafe.Pointer(sortSpec.TOPTR()))
-	}
-	switch query.(type) {
-	case string:
-		queryStringC := clownfish.NewString(query.(string))
-		err = clownfish.TrapErr(func() {
-			hitsC := C.LUCY_Searcher_Hits(self,
-				(*C.cfish_Obj)(unsafe.Pointer(queryStringC.TOPTR())),
-				C.uint32_t(offset), C.uint32_t(numWanted), sortSpecC)
-			hits = WRAPHits(unsafe.Pointer(hitsC))
-		})
-	default:
-		panic("TODO: support Query objects")
-	}
+	self := (*C.lucy_Searcher)(clownfish.Unwrap(s, "s"))
+	sortSpecC := (*C.lucy_SortSpec)(clownfish.UnwrapNullable(sortSpec))
+	queryC := (*C.cfish_Obj)(clownfish.GoToClownfish(query, unsafe.Pointer(C.CFISH_OBJ), false))
+	defer C.cfish_decref(unsafe.Pointer(queryC))
+	err = clownfish.TrapErr(func() {
+		hitsC := C.LUCY_Searcher_Hits(self, queryC,
+			C.uint32_t(offset), C.uint32_t(numWanted), sortSpecC)
+		hits = WRAPHits(unsafe.Pointer(hitsC))
+	})
 	return hits, err
 }
 


Mime
View raw message