Adapt custom Go bindings for autogen.

For classes with Go bindings which use custom struct layouts or spec
custom methods, adapt for new autogenerated CFC interface.


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

Branch: refs/heads/master
Commit: ec9bb9625047de938d67c9850c65bbcd8db5e4a5
Parents: 6a96d8f
Author: Marvin Humphrey <[email protected]>
Authored: Sun May 3 11:13:17 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Sun May 3 11:15:54 2015 -0700

----------------------------------------------------------------------
 go/build.go       | 27 +++++++++++++++++++++++++++
 go/lucy/index.go  |  7 -------
 go/lucy/plan.go   |  5 -----
 go/lucy/search.go | 49 ++++++++++++++++++++++++++++++++-----------------
 4 files changed, 59 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/ec9bb962/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 96ac2e5..43957d2 100644
--- a/go/build.go
+++ b/go/build.go
@@ -128,12 +128,39 @@ func runCFC() {
                goBinding.SetHeader(autogenHeader)
                goBinding.SetSuppressInit(true)
                parcel := cfc.FetchParcel("Lucy")
+               specClasses(parcel)
                packageDir := path.Join(buildDir, "lucy")
                goBinding.WriteBindings(parcel, packageDir)
                hierarchy.WriteLog()
        }
 }
 
+func specClasses(parcel *cfc.Parcel) {
+       indexerBinding := cfc.NewGoClass(parcel, "Lucy::Index::Indexer")
+       indexerBinding.SpecMethod("", "Close() error")
+       indexerBinding.SpecMethod("Add_Doc", "AddDoc(doc interface{}) error")
+       indexerBinding.SpecMethod("Commit", "Commit() error")
+       indexerBinding.SetSuppressStruct(true)
+       indexerBinding.Register()
+
+       schemaBinding := cfc.NewGoClass(parcel, "Lucy::Plan::Schema")
+       schemaBinding.SpecMethod("Spec_Field",
+               "SpecField(field string, fieldType FieldType)")
+       schemaBinding.Register()
+
+       searcherBinding := cfc.NewGoClass(parcel, "Lucy::Search::Searcher")
+       searcherBinding.SpecMethod("Hits",
+               "Hits(query interface{}, offset uint32, numWanted uint32, 
sortSpec SortSpec) (Hits, error)")
+       searcherBinding.SpecMethod("Close", "Close() error")
+       searcherBinding.Register()
+
+       hitsBinding := cfc.NewGoClass(parcel, "Lucy::Search::Hits")
+       hitsBinding.SpecMethod("Next", "Next(hit interface{}) bool")
+       hitsBinding.SpecMethod("", "Error() error")
+       hitsBinding.SetSuppressStruct(true)
+       hitsBinding.Register()
+}
+
 func build() {
        configure()
        runCFC()

http://git-wip-us.apache.org/repos/asf/lucy/blob/ec9bb962/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index c6fd275..a55771e 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -33,13 +33,6 @@ import "strings"
 import "unsafe"
 import 
"git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 
-type Indexer interface {
-       clownfish.Obj
-       Close() error
-       AddDoc(doc interface{}) error
-       Commit() error
-}
-
 type IndexerIMP struct {
        clownfish.ObjIMP
        fieldNames map[string]clownfish.String

http://git-wip-us.apache.org/repos/asf/lucy/blob/ec9bb962/go/lucy/plan.go
----------------------------------------------------------------------
diff --git a/go/lucy/plan.go b/go/lucy/plan.go
index a4aad5c..c11c1e0 100644
--- a/go/lucy/plan.go
+++ b/go/lucy/plan.go
@@ -25,11 +25,6 @@ import "unsafe"
 
 import 
"git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 
-type Schema interface {
-       clownfish.Obj
-       SpecField(field string, fieldType FieldType)
-}
-
 func NewSchema() Schema {
        cfObj := C.lucy_Schema_new()
        return WRAPSchema(unsafe.Pointer(cfObj))

http://git-wip-us.apache.org/repos/asf/lucy/blob/ec9bb962/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index dd99b80..c71048b 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -34,18 +34,6 @@ import "unsafe"
 
 import 
"git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
 
-type Searcher interface {
-       clownfish.Obj
-       Hits(query interface{}, offset uint32, numWanted uint32, sortSpec 
SortSpec) (Hits, error)
-       Close() error
-}
-
-type Hits interface {
-       clownfish.Obj
-       Next(hit interface{}) bool
-       Error() error
-}
-
 type HitsIMP struct {
        clownfish.ObjIMP
        err error
@@ -68,15 +56,24 @@ func OpenIndexSearcher(index interface{}) (obj 
IndexSearcher, err error) {
 }
 
 func (obj *IndexSearcherIMP) Close() error {
-       self := ((*C.lucy_IndexSearcher)(unsafe.Pointer(obj.TOPTR())))
+       return doClose(obj)
+}
+
+func (obj *IndexSearcherIMP) Hits(query interface{}, offset uint32, numWanted 
uint32,
+       sortSpec SortSpec) (hits Hits, err error) {
+       return doHits(obj, query, offset, numWanted, sortSpec)
+}
+
+func doClose(obj Searcher) error {
+       self := ((*C.lucy_Searcher)(unsafe.Pointer(obj.TOPTR())))
        return clownfish.TrapErr(func() {
-               C.LUCY_IxSearcher_Close(self)
+               C.LUCY_Searcher_Close(self)
        })
 }
 
-func (obj *IndexSearcherIMP) Hits(query interface{}, offset uint32, numWanted 
uint32,
+func doHits(obj Searcher, query interface{}, offset uint32, numWanted uint32,
        sortSpec SortSpec) (hits Hits, err error) {
-       self := ((*C.lucy_IndexSearcher)(unsafe.Pointer(obj.TOPTR())))
+       self := ((*C.lucy_Searcher)(unsafe.Pointer(obj.TOPTR())))
        var sortSpecC *C.lucy_SortSpec
        if sortSpec != nil {
                sortSpecC = (*C.lucy_SortSpec)(unsafe.Pointer(sortSpec.TOPTR()))
@@ -85,7 +82,7 @@ func (obj *IndexSearcherIMP) Hits(query interface{}, offset 
uint32, numWanted ui
        case string:
                queryStringC := clownfish.NewString(query.(string))
                err = clownfish.TrapErr(func() {
-                       hitsC := C.LUCY_IxSearcher_Hits(self,
+                       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))
@@ -96,6 +93,24 @@ func (obj *IndexSearcherIMP) Hits(query interface{}, offset 
uint32, numWanted ui
        return hits, err
 }
 
+func (obj *SearcherIMP) Close() error {
+       return doClose(obj)
+}
+
+func (obj *SearcherIMP) Hits(query interface{}, offset uint32, numWanted 
uint32,
+       sortSpec SortSpec) (hits Hits, err error) {
+       return doHits(obj, query, offset, numWanted, sortSpec)
+}
+
+func (obj *PolySearcherIMP) Close() error {
+       return doClose(obj)
+}
+
+func (obj *PolySearcherIMP) Hits(query interface{}, offset uint32, numWanted 
uint32,
+       sortSpec SortSpec) (hits Hits, err error) {
+       return doHits(obj, query, offset, numWanted, sortSpec)
+}
+
 func (obj *HitsIMP) Next(hit interface{}) bool {
        self := ((*C.lucy_Hits)(unsafe.Pointer(obj.TOPTR())))
        // TODO: accept a HitDoc object and populate score.

Reply via email to