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/12/28 21:10:59 UTC
[12/16] lucy git commit: Tune and test Go bindings for
PostingListReader.
Tune and test Go bindings for PostingListReader.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/e5e4232b
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/e5e4232b
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/e5e4232b
Branch: refs/heads/master
Commit: e5e4232b6c0c8d22f46c6db5430fb92ee949c855
Parents: 3358bc2
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Thu Dec 10 19:03:15 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Thu Dec 10 19:04:59 2015 -0800
----------------------------------------------------------------------
go/build.go | 4 ++++
go/lucy/index.go | 16 ++++++++++++++++
go/lucy/index_test.go | 19 ++++++++++++++++++-
3 files changed, 38 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/e5e4232b/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 36b487d..604a9a9 100644
--- a/go/build.go
+++ b/go/build.go
@@ -224,6 +224,10 @@ func specClasses(parcel *cfc.Parcel) {
lexReaderBinding.SpecMethod("Fetch_Term_Info", "fetchTermInfo(string, interface{}) (TermInfo, error)")
lexReaderBinding.Register()
+ pListReaderBinding := cfc.NewGoClass(parcel, "Lucy::Index::PostingListReader")
+ pListReaderBinding.SpecMethod("Posting_List", "PostingList(string, interface{}) (PostingList, error)")
+ pListReaderBinding.Register()
+
bgMergerBinding := cfc.NewGoClass(parcel, "Lucy::Index::BackgroundMerger")
bgMergerBinding.SpecMethod("Prepare_Commit", "PrepareCommit() error")
bgMergerBinding.SpecMethod("Commit", "Commit() error")
http://git-wip-us.apache.org/repos/asf/lucy/blob/e5e4232b/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index a0e3396..1f5a752 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -22,6 +22,7 @@ package lucy
#include "Lucy/Index/DataReader.h"
#include "Lucy/Index/DocReader.h"
#include "Lucy/Index/LexiconReader.h"
+#include "Lucy/Index/PostingListReader.h"
#include "Lucy/Index/HighlightReader.h"
#include "Lucy/Index/SortReader.h"
#include "Lucy/Index/IndexManager.h"
@@ -529,6 +530,21 @@ func (lr *LexiconReaderIMP) fetchTermInfo(field string, term interface{}) (retva
return retval, err
}
+func (p *PostingListReaderIMP) PostingList(field string, term interface{}) (retval PostingList, err error) {
+ err = clownfish.TrapErr(func() {
+ self := (*C.lucy_PostingListReader)(clownfish.Unwrap(p, "p"))
+ fieldC := (*C.cfish_String)(clownfish.GoToClownfish(field, unsafe.Pointer(C.CFISH_STRING), false))
+ defer C.cfish_decref(unsafe.Pointer(fieldC))
+ termC := (*C.cfish_Obj)(clownfish.GoToClownfish(term, unsafe.Pointer(C.CFISH_OBJ), true))
+ defer C.cfish_decref(unsafe.Pointer(termC))
+ retvalCF := C.LUCY_PListReader_Posting_List(self, fieldC, termC)
+ if retvalCF != nil {
+ retval = clownfish.ToGo(unsafe.Pointer(retvalCF)).(PostingList)
+ }
+ })
+ return retval, err
+}
+
func (h *HighlightReaderIMP) FetchDocVec(docID int32) (retval DocVector, err error) {
err = clownfish.TrapErr(func() {
self := (*C.lucy_HighlightReader)(clownfish.Unwrap(h, "h"))
http://git-wip-us.apache.org/repos/asf/lucy/blob/e5e4232b/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index 18d1e22..0143fcf 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -681,7 +681,7 @@ func TestPostingListBasics(t *testing.T) {
ixReader, _ := OpenIndexReader(folder, nil, nil)
segReaders := ixReader.SegReaders()
pListReader := segReaders[0].Fetch("Lucy::Index::PostingListReader").(PostingListReader)
- pList := pListReader.PostingList("content", nil)
+ pList, _ := pListReader.PostingList("content", nil)
pList.Seek("b")
if docFreq := pList.GetDocFreq(); docFreq != 2 {
t.Errorf("GetDocFreq: %d", docFreq)
@@ -849,6 +849,23 @@ func TestLexReaderMisc(t *testing.T) {
runDataReaderCommon(t, lexReader, false)
}
+func TestPostingListReaderMisc(t *testing.T) {
+ folder := createTestIndex("a", "b", "c")
+ ixReader, _ := OpenIndexReader(folder, nil, nil)
+ segReaders := ixReader.SegReaders()
+ pListReader := segReaders[0].Fetch("Lucy::Index::PostingListReader").(PostingListReader)
+ if got, err := pListReader.PostingList("content", nil); got == nil || err != nil {
+ t.Errorf("PostingList should succeed: %v", err)
+ }
+ if got, err := pListReader.PostingList("content", "foo"); got == nil || err != nil {
+ t.Errorf("PostingList with term should succeed: %v", err)
+ }
+ if got, err := pListReader.PostingList("nope", nil); got != nil || err != nil {
+ t.Errorf("PostingList for non-field should return nil: %v", err)
+ }
+ runDataReaderCommon(t, pListReader, false)
+}
+
func TestHighlightReaderMisc(t *testing.T) {
folder := createTestIndex("a", "b", "c")
ixReader, _ := OpenIndexReader(folder, nil, nil)