lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [04/13] lucy git commit: Add error to Go binding for MakeMatcher.
Date Tue, 24 Nov 2015 23:38:26 GMT
Add error to Go binding for MakeMatcher.


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

Branch: refs/heads/master
Commit: 6d0a55f7387df4714386b7ffce9ba554c0c384f4
Parents: 3d636a1
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Nov 12 19:38:23 2015 -0800
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Fri Nov 20 16:43:37 2015 -0800

----------------------------------------------------------------------
 go/build.go            |  4 ++++
 go/lucy/search.go      | 16 ++++++++++++++++
 go/lucy/search_test.go |  5 +++++
 3 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/6d0a55f7/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index ccd606b..fc73f64 100644
--- a/go/build.go
+++ b/go/build.go
@@ -228,6 +228,10 @@ func specClasses(parcel *cfc.Parcel) {
 	hitsBinding.SetSuppressStruct(true)
 	hitsBinding.Register()
 
+	compilerBinding := cfc.NewGoClass(parcel, "Lucy::Search::Compiler")
+	compilerBinding.SpecMethod("Make_Matcher", "MakeMatcher(SegReader, bool) (Matcher, error)")
+	compilerBinding.Register()
+
 	andQueryBinding := cfc.NewGoClass(parcel, "Lucy::Search::ANDQuery")
 	andQueryBinding.SetSuppressCtor(true)
 	andQueryBinding.Register()

http://git-wip-us.apache.org/repos/asf/lucy/blob/6d0a55f7/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index 147af63..c539044 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -25,6 +25,7 @@ package lucy
 #include "Lucy/Search/Hits.h"
 #include "Lucy/Search/IndexSearcher.h"
 #include "Lucy/Search/Query.h"
+#include "Lucy/Search/Compiler.h"
 #include "Lucy/Search/Searcher.h"
 #include "Lucy/Search/ANDQuery.h"
 #include "Lucy/Search/ORQuery.h"
@@ -244,6 +245,21 @@ func (td *TopDocsIMP) GetMatchDocs() []MatchDoc {
 	return slice
 }
 
+func (c *CompilerIMP) MakeMatcher(reader SegReader, needScore bool) (retval Matcher, err
error) {
+	err = clownfish.TrapErr(func() {
+		self := (*C.lucy_Compiler)(clownfish.Unwrap(c, "c"))
+		readerCF := (*C.lucy_SegReader)(clownfish.Unwrap(reader, "reader"))
+		retvalCF := C.LUCY_Compiler_Make_Matcher(self, readerCF, C.bool(needScore))
+		if retvalCF != nil {
+			retval = clownfish.WRAPAny(unsafe.Pointer(retvalCF)).(Matcher)
+		}
+	})
+	if err != nil || retval == nil {
+		return nil, err
+	}
+	return retval, err
+}
+
 func NewANDQuery(children []Query) ANDQuery {
 	vec := clownfish.NewVector(len(children))
 	for _, child := range children {

http://git-wip-us.apache.org/repos/asf/lucy/blob/6d0a55f7/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index 50d7fae..a92708c 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -95,6 +95,11 @@ func TestTermCompilerMisc(t *testing.T) {
 	checkQuerySerialize(t, compiler) 
 	checkQueryEquals(t, compiler)
 	checkQueryToStringHasFoo(t, compiler)
+	segReaders := searcher.GetReader().SegReaders()
+	matcher, err := compiler.MakeMatcher(segReaders[0].(SegReader), false)
+	if matcher == nil || err != nil {
+		t.Errorf("MakeMatcher: %v", err)
+	}
 }
 
 func TestTermCompilerWeighting(t *testing.T) {


Mime
View raw message