You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2015/09/28 21:52:20 UTC
[04/14] lucy git commit: Tune and test TopDocs Go binding.
Tune and test TopDocs Go binding.
Use slice of MatchDocs rather than Vector.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/d0388c8c
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/d0388c8c
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/d0388c8c
Branch: refs/heads/master
Commit: d0388c8c705dba826ab828c35d0690498da30dd1
Parents: b8b4b8e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Thu Sep 10 19:37:45 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Tue Sep 15 15:54:50 2015 -0700
----------------------------------------------------------------------
go/build.go | 6 ++++++
go/lucy/search.go | 33 +++++++++++++++++++++++++++++++++
go/lucy/search_test.go | 27 +++++++++++++++++++++++++++
3 files changed, 66 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/d0388c8c/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 10ec5cf..f18252e 100644
--- a/go/build.go
+++ b/go/build.go
@@ -191,6 +191,12 @@ func specClasses(parcel *cfc.Parcel) {
mockMatcherBinding := cfc.NewGoClass(parcel, "LucyX::Search::MockMatcher")
mockMatcherBinding.SetSuppressCtor(true)
mockMatcherBinding.Register()
+
+ topDocsBinding := cfc.NewGoClass(parcel, "Lucy::Search::TopDocs")
+ topDocsBinding.SetSuppressCtor(true)
+ topDocsBinding.SpecMethod("Set_Match_Docs", "SetMatchDocs([]MatchDoc)")
+ topDocsBinding.SpecMethod("Get_Match_Docs", "GetMatchDocs() []MatchDoc")
+ topDocsBinding.Register()
}
func build() {
http://git-wip-us.apache.org/repos/asf/lucy/blob/d0388c8c/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index 18ac6bc..4865072 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -27,11 +27,13 @@ package lucy
#include "Lucy/Search/ANDMatcher.h"
#include "Lucy/Search/ORMatcher.h"
#include "Lucy/Search/SeriesMatcher.h"
+#include "Lucy/Search/TopDocs.h"
#include "Lucy/Document/HitDoc.h"
#include "LucyX/Search/MockMatcher.h"
#include "Clownfish/Blob.h"
#include "Clownfish/Hash.h"
#include "Clownfish/HashIterator.h"
+#include "Clownfish/Vector.h"
static inline void
float32_set(float *floats, size_t i, float value) {
@@ -175,6 +177,37 @@ func (obj *HitsIMP) Error() error {
return obj.err
}
+func NewTopDocs(matchDocs []MatchDoc, totalHits uint32) TopDocs {
+ vec := clownfish.NewVector(len(matchDocs))
+ for _, matchDoc := range matchDocs {
+ vec.Push(matchDoc)
+ }
+ cfObj := C.lucy_TopDocs_new(((*C.cfish_Vector)(clownfish.Unwrap(vec, "matchDocs"))),
+ C.uint32_t(totalHits))
+ return WRAPTopDocs(unsafe.Pointer(cfObj))
+}
+
+func (td *TopDocsIMP) SetMatchDocs(matchDocs []MatchDoc) {
+ self := (*C.lucy_TopDocs)(clownfish.Unwrap(td, "td"))
+ vec := clownfish.NewVector(len(matchDocs))
+ for _, matchDoc := range matchDocs {
+ vec.Push(matchDoc)
+ }
+ C.LUCY_TopDocs_Set_Match_Docs(self, (*C.cfish_Vector)(clownfish.Unwrap(vec, "matchDocs")))
+}
+
+func (td *TopDocsIMP) GetMatchDocs() []MatchDoc {
+ self := (*C.lucy_TopDocs)(clownfish.Unwrap(td, "td"))
+ vec := C.LUCY_TopDocs_Get_Match_Docs(self)
+ length := int(C.CFISH_Vec_Get_Size(vec))
+ slice := make([]MatchDoc, length)
+ for i := 0; i < length; i++ {
+ elem := C.cfish_incref(unsafe.Pointer(C.CFISH_Vec_Fetch(vec, C.size_t(i))))
+ slice[i] = WRAPMatchDoc(unsafe.Pointer(elem))
+ }
+ return slice
+}
+
func NewANDQuery(children []Query) ANDQuery {
vec := clownfish.NewVector(len(children))
for _, child := range children {
http://git-wip-us.apache.org/repos/asf/lucy/blob/d0388c8c/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index 83fdc71..4225799 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -327,3 +327,30 @@ func TestSeriesMatcherBasics(t *testing.T) {
matcher := NewSeriesMatcher([]Matcher{a, b, c}, []int32{0, 42, 80})
checkMatcher(t, matcher, false)
}
+
+func TestTopDocsBasics(t *testing.T) {
+ matchDocs := []MatchDoc{
+ NewMatchDoc(42, 2.0, nil),
+ NewMatchDoc(100, 3.0, nil),
+ }
+ td := NewTopDocs(matchDocs, 50)
+ td.SetTotalHits(20)
+ if totalHits := td.GetTotalHits(); totalHits != 20 {
+ t.Errorf("Expected 20 total hits, got %d", totalHits)
+ }
+ td.SetMatchDocs(matchDocs)
+ fetched := td.GetMatchDocs()
+ if docID := fetched[0].GetDocID(); docID != 42 {
+ t.Errorf("Set/Get MatchDocs expected 42, got %d", docID)
+ }
+
+ folder := NewRAMFolder("")
+ outstream := folder.OpenOut("foo")
+ td.Serialize(outstream)
+ outstream.Close()
+ inStream := folder.OpenIn("foo")
+ dupe := clownfish.GetClass(td).MakeObj().(TopDocs).Deserialize(inStream)
+ if dupe.GetTotalHits() != td.GetTotalHits() {
+ t.Errorf("Failed round-trip serializetion of TopDocs")
+ }
+}