lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [04/15] lucy git commit: Tune and test Go bindings for Indexer.
Date Sat, 07 Nov 2015 02:48:53 GMT
Tune and test Go bindings for Indexer.


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

Branch: refs/heads/master
Commit: 71dd0aa830e6dca814c0e5489074eea28307e3ee
Parents: a22a445
Author: Marvin Humphrey <marvin@rectangular.com>
Authored: Thu Oct 29 11:05:01 2015 -0700
Committer: Marvin Humphrey <marvin@rectangular.com>
Committed: Sat Oct 31 15:31:15 2015 -0700

----------------------------------------------------------------------
 go/build.go           |  5 +++
 go/lucy/index.go      | 42 ++++++++++++++++++++++
 go/lucy/index_test.go | 89 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 136 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/71dd0aa8/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 0691f6e..eaf896b 100644
--- a/go/build.go
+++ b/go/build.go
@@ -148,6 +148,11 @@ 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("Add_Index", "AddIndex(interface{}) error")
+	indexerBinding.SpecMethod("Delete_By_Term", "DeleteByTerm(string, interface{}) error")
+	indexerBinding.SpecMethod("Delete_By_Query", "DeleteByQuery(Query) error")
+	indexerBinding.SpecMethod("Delete_By_Doc_ID", "DeleteByDocID(int32) error")
+	indexerBinding.SpecMethod("Prepare_Commit", "PrepareCommit() error")
 	indexerBinding.SpecMethod("Commit", "Commit() error")
 	indexerBinding.SetSuppressStruct(true)
 	indexerBinding.Register()

http://git-wip-us.apache.org/repos/asf/lucy/blob/71dd0aa8/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index 0ec4c97..3b9a8f5 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -174,6 +174,48 @@ func (obj *IndexerIMP) findRealField(name string) (string, error) {
 	return "", clownfish.NewErr(fmt.Sprintf("Unknown field: '%v'", name))
 }
 
+func (obj *IndexerIMP) AddIndex(index interface{}) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Indexer)(clownfish.Unwrap(obj, "obj"))
+		indexC := (*C.cfish_Obj)(clownfish.GoToClownfish(index, unsafe.Pointer(C.CFISH_OBJ), false))
+		defer C.cfish_decref(unsafe.Pointer(indexC))
+		C.LUCY_Indexer_Add_Index(self, indexC)
+	})
+}
+
+func (obj *IndexerIMP) DeleteByTerm(field string, term interface{}) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Indexer)(clownfish.Unwrap(obj, "obj"))
+		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), false))
+		defer C.cfish_decref(unsafe.Pointer(termC))
+		C.LUCY_Indexer_Delete_By_Term(self, fieldC, termC)
+	})
+}
+
+func (obj *IndexerIMP) DeleteByQuery(query Query) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Indexer)(clownfish.Unwrap(obj, "obj"))
+		queryC := (*C.lucy_Query)(clownfish.Unwrap(query, "query"))
+		C.LUCY_Indexer_Delete_By_Query(self, queryC)
+	})
+}
+
+func (obj *IndexerIMP) DeleteByDocID(docID int32) error {
+	return clownfish.TrapErr(func() {
+		self := (*C.lucy_Indexer)(clownfish.Unwrap(obj, "obj"))
+		C.LUCY_Indexer_Delete_By_Doc_ID(self, C.int32_t(docID))
+	})
+}
+
+func (obj *IndexerIMP) PrepareCommit() error {
+	self := ((*C.lucy_Indexer)(unsafe.Pointer(obj.TOPTR())))
+	return clownfish.TrapErr(func() {
+		C.LUCY_Indexer_Prepare_Commit(self)
+	})
+}
+
 func (obj *IndexerIMP) Commit() error {
 	self := ((*C.lucy_Indexer)(unsafe.Pointer(obj.TOPTR())))
 	return clownfish.TrapErr(func() {

http://git-wip-us.apache.org/repos/asf/lucy/blob/71dd0aa8/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index 5967a31..0afdf92 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -17,6 +17,7 @@
 package lucy
 
 import "testing"
+import "os"
 
 func TestIndexerAddDoc(t *testing.T) {
 	schema := createTestSchema()
@@ -37,3 +38,91 @@ func TestIndexerAddDoc(t *testing.T) {
 		t.Errorf("Didn't index all docs -- DocMax: %d", got)
 	}
 }
+
+func TestIndexerAddIndex(t *testing.T) {
+	var err error
+	origIndex := "_test_go_indexer_add_index"
+	defer os.RemoveAll(origIndex)
+	schema := createTestSchema()
+	indexer, err := OpenIndexer(&OpenIndexerArgs{
+		Create: true,
+		Index:  origIndex,
+		Schema: schema,
+	})
+	if err != nil {
+		t.Errorf("OpenIndexer: %v", err)
+		return
+	}
+	err = indexer.AddDoc(&testDoc{Content: "foo"})
+	if err != nil {
+		t.Errorf("AddDoc: %v", err)
+	}
+	err = indexer.Commit()
+	if err != nil {
+		t.Errorf("Commit FS index: %v", err)
+	}
+
+	indexer, _ = OpenIndexer(&OpenIndexerArgs{
+		Create: true,
+		Index:  NewRAMFolder(""),
+		Schema: schema,
+	})
+	err = indexer.AddIndex(origIndex)
+	if err != nil {
+		t.Errorf("AddIndex: %v", err)
+	}
+	err = indexer.Commit()
+	if err != nil {
+		t.Errorf("AddIndex: %v", err)
+	}
+}
+
+func TestIndexerDeletions(t *testing.T) {
+	index := createTestIndex("foo", "bar", "baz", "gazi")
+	indexer, _ := OpenIndexer(&OpenIndexerArgs{Index: index})
+	err := indexer.DeleteByTerm("content", "foo")
+	if err != nil {
+		t.Errorf("DeleteByTerm: %v", err)
+	}
+	indexer.DeleteByQuery(NewTermQuery("content", "bar"))
+	if err != nil {
+		t.Errorf("DeleteByQuery: %v", err)
+	}
+	indexer.DeleteByDocID(3)
+	if err != nil {
+		t.Errorf("DeleteByDocID: %v", err)
+	}
+	err = indexer.Commit()
+	if err != nil {
+		t.Errorf("Commit: %v", err)
+	}
+	searcher, _ := OpenIndexSearcher(index)
+	if count := searcher.GetReader().DocCount(); count != 1 {
+		t.Errorf("Some deletions didn't go through (count=%d)", count)
+	}
+}
+
+func TestIndexerMisc(t *testing.T) {
+	var err error
+	index := createTestIndex("foo", "bar", "baz")
+	indexer, _ := OpenIndexer(&OpenIndexerArgs{Index: index})
+	if _, ok := indexer.GetSchema().(Schema); !ok {
+		t.Errorf("GetSchema")
+	}
+	if _, ok := indexer.GetStockDoc().(Doc); !ok {
+		t.Errorf("GetStockDoc")
+	}
+	if _, ok := indexer.GetSegWriter().(SegWriter); !ok {
+		t.Errorf("GetSegWriter")
+	}
+	indexer.AddDoc(&testDoc{Content: "gazi"})
+	indexer.Optimize()
+	err = indexer.PrepareCommit()
+	if err != nil {
+		t.Errorf("PrepareCommit: %v", err)
+	}
+	err = indexer.Commit()
+	if err != nil {
+		t.Errorf("Commit: %v", err)
+	}
+}


Mime
View raw message