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:11:02 UTC
[15/16] lucy git commit: Tune and test Go bindings for SegWriter.
Tune and test Go bindings for SegWriter.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/126c6ba8
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/126c6ba8
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/126c6ba8
Branch: refs/heads/master
Commit: 126c6ba8907c2f134c9921cafe8d7dc74f1fbc5d
Parents: 2932054
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Mon Dec 21 12:38:25 2015 -0800
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Mon Dec 21 12:38:25 2015 -0800
----------------------------------------------------------------------
go/build.go | 5 +++++
go/lucy/index.go | 16 ++++++++++++++++
go/lucy/index_test.go | 17 +++++++++++++++++
3 files changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/126c6ba8/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 82bcd9c..e3fc79d 100644
--- a/go/build.go
+++ b/go/build.go
@@ -236,6 +236,11 @@ func specClasses(parcel *cfc.Parcel) {
dwBinding.SpecMethod("Finish", "Finish() error")
dwBinding.Register()
+ segWriterBinding := cfc.NewGoClass(parcel, "Lucy::Index::SegWriter")
+ segWriterBinding.SpecMethod("Prep_Seg_Dir", "PrepSegDir() error")
+ segWriterBinding.SpecMethod("Add_Doc", "AddDoc(Doc, float32) error")
+ segWriterBinding.Register()
+
delWriterBinding := cfc.NewGoClass(parcel, "Lucy::Index::DeletionsWriter")
delWriterBinding.SpecMethod("Delete_By_Term", "DeleteByTerm(string, interface{}) error")
delWriterBinding.SpecMethod("Delete_By_Query", "DeleteByQuery(Query) error")
http://git-wip-us.apache.org/repos/asf/lucy/blob/126c6ba8/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index 67ec832..6f627f0 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -21,6 +21,7 @@ package lucy
#include "Lucy/Index/IndexReader.h"
#include "Lucy/Index/DataReader.h"
#include "Lucy/Index/DataWriter.h"
+#include "Lucy/Index/SegWriter.h"
#include "Lucy/Index/DeletionsWriter.h"
#include "Lucy/Index/DocReader.h"
#include "Lucy/Index/LexiconReader.h"
@@ -280,6 +281,21 @@ func (d *DataWriterIMP) Finish() error {
})
}
+func (s *SegWriterIMP) PrepSegDir() error {
+ return clownfish.TrapErr(func() {
+ self := (*C.lucy_SegWriter)(clownfish.Unwrap(s, "s"))
+ C.LUCY_SegWriter_Prep_Seg_Dir(self)
+ })
+}
+
+func (s *SegWriterIMP) AddDoc(doc Doc, boost float32) error {
+ return clownfish.TrapErr(func() {
+ self := (*C.lucy_SegWriter)(clownfish.Unwrap(s, "s"))
+ docCF := (*C.lucy_Doc)(clownfish.Unwrap(doc, "doc"))
+ C.LUCY_SegWriter_Add_Doc(self, docCF, C.float(boost))
+ })
+}
+
func (d *DeletionsWriterIMP) DeleteByTerm(field string, term interface{}) error {
return clownfish.TrapErr(func() {
self := (*C.lucy_DeletionsWriter)(clownfish.Unwrap(d, "d"))
http://git-wip-us.apache.org/repos/asf/lucy/blob/126c6ba8/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index 9f2aca9..bc6bac4 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -994,3 +994,20 @@ func TestDeletionsWriterMisc(t *testing.T) {
t.Errorf("segDeletions: %v", err)
}
}
+
+func TestSegWriterMisc(t *testing.T) {
+ index := createTestIndex("a", "b", "c")
+ ixReader, _ := OpenIndexReader(index, nil, nil)
+ polyReader := ixReader.(PolyReader)
+ schema := polyReader.GetSchema()
+ segment := NewSegment(2)
+ snapshot := polyReader.GetSnapshot()
+ segWriter := NewSegWriter(schema, snapshot, segment, polyReader)
+ if err := segWriter.PrepSegDir(); err != nil {
+ t.Errorf("PrepSegDir: %v", err)
+ }
+ doc := NewDoc(1)
+ if err := segWriter.AddDoc(doc, 1.0); err != nil {
+ t.Errorf("AddDoc: %v", err)
+ }
+}