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/12 00:00:26 UTC
[01/16] lucy git commit: Register WRAP functions in custom `init`.
Repository: lucy
Updated Branches:
refs/heads/master c94acc5b7 -> 79a776911
Register WRAP functions in custom `init`.
Since Lucy has its own custom `init` function, it needs to invoke
`initWRAP` manually in order for `clownfish.WRAPAny` to know about
Lucy-specific types.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/3d4a0b6c
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/3d4a0b6c
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/3d4a0b6c
Branch: refs/heads/master
Commit: 3d4a0b6cf0cc0131b10c452dba7bd91414780b3f
Parents: b69adb8
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 11 13:08:33 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 16:17:59 2015 -0700
----------------------------------------------------------------------
go/lucy/lucy.go | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/3d4a0b6c/go/lucy/lucy.go
----------------------------------------------------------------------
diff --git a/go/lucy/lucy.go b/go/lucy/lucy.go
index fcddfbd..37d7f1c 100644
--- a/go/lucy/lucy.go
+++ b/go/lucy/lucy.go
@@ -191,6 +191,7 @@ func init() {
C.GOLUCY_glue_exported_symbols()
C.lucy_bootstrap_parcel()
registry = newObjRegistry(16)
+ initWRAP()
}
//export GOLUCY_RegexTokenizer_init
[05/16] lucy git commit: Test Go bindings for Query classes.
Posted by ma...@apache.org.
Test Go bindings for Query classes.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/c0bdb9c4
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/c0bdb9c4
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/c0bdb9c4
Branch: refs/heads/master
Commit: c0bdb9c44fd2e12b56f61e1b865df679147a992f
Parents: a28275e
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 11 19:44:16 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:24:53 2015 -0700
----------------------------------------------------------------------
go/lucy/search_test.go | 251 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 251 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/c0bdb9c4/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
new file mode 100644
index 0000000..d566553
--- /dev/null
+++ b/go/lucy/search_test.go
@@ -0,0 +1,251 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package lucy
+
+import "testing"
+import "strings"
+import "reflect"
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+
+func checkQuerySerialize(t *testing.T, query Query) {
+ folder := NewRAMFolder("")
+ outStream := folder.OpenOut("foo")
+ query.Serialize(outStream)
+ outStream.Close()
+ inStream := folder.OpenIn("foo")
+ dupe := clownfish.GetClass(query).MakeObj().(Query).Deserialize(inStream)
+ if !query.Equals(dupe) {
+ t.Errorf("Unsuccessful serialization round trip -- expected '%v', got '%v'",
+ query.ToString(), dupe.ToString())
+ }
+}
+
+func checkQueryDumpLoad(t *testing.T, query Query) {
+ dupe := clownfish.GetClass(query).MakeObj().(Query)
+ dupe = dupe.Load(query.Dump()).(Query)
+ if !query.Equals(dupe) {
+ t.Errorf("Unsuccessful Dump/Load round trip -- expected '%v', got '%v'",
+ query.ToString(), dupe.ToString())
+ }
+}
+
+func checkQueryEquals(t *testing.T, query Query) {
+ if !query.Equals(query) {
+ t.Error("Equals self")
+ }
+ if query.Equals("blah") {
+ t.Error("Equals against Go string")
+ }
+}
+
+func checkQueryMakeCompiler(t *testing.T, query Query) {
+ index := createTestIndex("foo", "bar", "baz")
+ searcher, _ := OpenIndexSearcher(index)
+ compiler := query.MakeCompiler(searcher, 1.0, false)
+ if got, ok := compiler.(Compiler); !ok {
+ t.Error("MakeCompiler failed: got '%v'", got)
+ }
+}
+
+// Test whether ToString() yields a string which contains "foo".
+func checkQueryToStringHasFoo(t *testing.T, query Query) {
+ if got := query.ToString(); !strings.Contains(got, "foo") {
+ t.Errorf("Unexpected stringification: '%v'", got)
+ }
+}
+
+func TestTermQueryMisc(t *testing.T) {
+ query := NewTermQuery("content", "foo")
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestTermQueryAccessors(t *testing.T) {
+ query := NewTermQuery("content", "foo")
+ if got := query.GetField(); got != "content" {
+ t.Errorf("Expected 'content', got '%v'", got)
+ }
+ if got := query.GetTerm().(string); got != "foo" {
+ t.Errorf("Expected 'foo', got '%v'", got)
+ }
+}
+
+func TestTermCompilerMisc(t *testing.T) {
+ folder := createTestIndex("foo", "bar", "baz")
+ searcher, _ := OpenIndexSearcher(folder)
+ query := NewTermQuery("content", "foo")
+ compiler := NewTermCompiler(query, searcher, 1.0)
+ checkQuerySerialize(t, compiler)
+ checkQueryEquals(t, compiler)
+ checkQueryToStringHasFoo(t, compiler)
+}
+
+func TestTermCompilerWeighting(t *testing.T) {
+ index := createTestIndex("foo", "bar", "baz")
+ searcher, _ := OpenIndexSearcher(index)
+ query := NewTermQuery("content", "foo")
+ compiler := NewTermCompiler(query, searcher, 1.0)
+ _ = compiler.SumOfSquaredWeights()
+ _ = compiler.GetWeight()
+ compiler.ApplyNormFactor(10.0)
+}
+
+func TestPhraseQueryMisc(t *testing.T) {
+ terms := []interface{}{"foo", "bar"}
+ query := NewPhraseQuery("content", terms)
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestPhraseQueryAccessors(t *testing.T) {
+ terms := []interface{}{"foo", "bar"}
+ query := NewPhraseQuery("content", terms)
+ if field := query.GetField(); field != "content" {
+ t.Errorf("Expected 'content', got '%v'", field)
+ }
+ if got := query.GetTerms(); !reflect.DeepEqual(terms, got) {
+ t.Errorf("Expected '%v', got '%v'", terms, got)
+ }
+}
+
+func TestPhraseCompilerMisc(t *testing.T) {
+ folder := createTestIndex("foo", "bar", "baz")
+ searcher, _ := OpenIndexSearcher(folder)
+ terms := []interface{}{"foo", "bar"}
+ query := NewPhraseQuery("content", terms)
+ compiler := NewPhraseCompiler(query, searcher, 1.0)
+ checkQuerySerialize(t, compiler)
+ checkQueryEquals(t, compiler)
+ checkQueryToStringHasFoo(t, compiler)
+}
+
+func TestPhraseCompilerWeighting(t *testing.T) {
+ index := createTestIndex("foo", "bar", "baz")
+ searcher, _ := OpenIndexSearcher(index)
+ terms := []interface{}{"foo", "bar"}
+ query := NewPhraseQuery("content", terms)
+ compiler := NewPhraseCompiler(query, searcher, 1.0)
+ _ = compiler.SumOfSquaredWeights()
+ _ = compiler.GetWeight()
+ compiler.ApplyNormFactor(10.0)
+}
+
+func TestANDQueryBasics(t *testing.T) {
+ children := []Query{
+ NewTermQuery("content", "foo"),
+ NewTermQuery("content", "bar"),
+ }
+ query := NewANDQuery(children)
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestORQueryBasics(t *testing.T) {
+ children := []Query{
+ NewTermQuery("content", "foo"),
+ NewTermQuery("content", "bar"),
+ }
+ query := NewORQuery(children)
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestReqOptQueryBasics(t *testing.T) {
+ req := NewTermQuery("content", "foo")
+ opt := NewTermQuery("content", "bar")
+ query := NewRequiredOptionalQuery(req, opt)
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestReqOptQueryAccessors(t *testing.T) {
+ req := NewTermQuery("content", "foo")
+ opt := NewTermQuery("content", "bar")
+ query := NewRequiredOptionalQuery(req, opt)
+ if query.GetRequiredQuery().TOPTR() != req.TOPTR() {
+ t.Errorf("GetRequiredQuery")
+ }
+ if query.GetOptionalQuery().TOPTR() != opt.TOPTR() {
+ t.Errorf("GetOptionalQuery")
+ }
+}
+
+func TestNOTQueryBasics(t *testing.T) {
+ negated := NewTermQuery("content", "foo")
+ query := NewNOTQuery(negated)
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestNOTQueryAccessors(t *testing.T) {
+ negated := NewTermQuery("content", "foo")
+ query := NewNOTQuery(negated)
+ if query.GetNegatedQuery().TOPTR() != negated.TOPTR() {
+ t.Errorf("GetNegatedQuery")
+ }
+}
+
+func TestMatchAllQueryBasics(t *testing.T) {
+ query := NewMatchAllQuery()
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+}
+
+func TestNOMatchQueryBasics(t *testing.T) {
+ query := NewNoMatchQuery()
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+}
+
+func TestRangeQueryBasics(t *testing.T) {
+ query := NewRangeQuery("content", "fab", "foo", true, true)
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryMakeCompiler(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
+
+func TestLeafQueryBasics(t *testing.T) {
+ query := NewLeafQuery("content", "foo")
+ checkQuerySerialize(t, query)
+ checkQueryDumpLoad(t, query)
+ checkQueryEquals(t, query)
+ checkQueryToStringHasFoo(t, query)
+}
[10/16] lucy git commit: Sanity check MockMatcher ctor args.
Posted by ma...@apache.org.
Sanity check MockMatcher ctor args.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/456a8253
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/456a8253
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/456a8253
Branch: refs/heads/master
Commit: 456a82532432ac314f7c06a3d9f27e90aacf2384
Parents: b76fe6a
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 16:55:46 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:23 2015 -0700
----------------------------------------------------------------------
core/LucyX/Search/MockMatcher.c | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/456a8253/core/LucyX/Search/MockMatcher.c
----------------------------------------------------------------------
diff --git a/core/LucyX/Search/MockMatcher.c b/core/LucyX/Search/MockMatcher.c
index 73a1b8d..1cce741 100644
--- a/core/LucyX/Search/MockMatcher.c
+++ b/core/LucyX/Search/MockMatcher.c
@@ -30,6 +30,12 @@ MockMatcher*
MockMatcher_init(MockMatcher *self, I32Array *doc_ids, Blob *scores) {
Matcher_init((Matcher*)self);
MockMatcherIVARS *const ivars = MockMatcher_IVARS(self);
+ size_t num_doc_ids = I32Arr_Get_Size(doc_ids);
+ size_t num_scores = scores ? Blob_Get_Size(scores) / sizeof(float) : 0;
+ if (scores != NULL && num_scores != num_doc_ids) {
+ THROW(ERR, "Num doc IDs != num scores (%u64, %u64)",
+ (uint64_t)num_doc_ids, (uint64_t)num_scores);
+ }
ivars->tick = -1;
ivars->size = I32Arr_Get_Size(doc_ids);
ivars->doc_ids = (I32Array*)INCREF(doc_ids);
[11/16] lucy git commit: Test I32Array Go bindings.
Posted by ma...@apache.org.
Test I32Array Go bindings.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/db2c25da
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/db2c25da
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/db2c25da
Branch: refs/heads/master
Commit: db2c25da42f9b34aaabfd7c89b009229d04a1063
Parents: a7aa779
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 17:43:39 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:24 2015 -0700
----------------------------------------------------------------------
go/lucy/object_test.go | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/db2c25da/go/lucy/object_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/object_test.go b/go/lucy/object_test.go
index 51ebe83..f78fd69 100644
--- a/go/lucy/object_test.go
+++ b/go/lucy/object_test.go
@@ -119,4 +119,13 @@ func TestBitVecBool(t *testing.T) {
}
}
-
+func TestI32ArrBasics(t *testing.T) {
+ arr := NewI32Array([]int32{42, 43})
+ if size := arr.GetSize(); size != 2 {
+ t.Errorf("Unexpected size: %d", size)
+ }
+ arr.Set(1, 101)
+ if got := arr.Get(1); got != 101 {
+ t.Errorf("Unexpected value: %d", got)
+ }
+}
[04/16] lucy git commit: Make NewANDQuery, NewORQuery take []Query.
Posted by ma...@apache.org.
Make NewANDQuery, NewORQuery take []Query.
Have the Go bindings for the ANDQuery and ORQuery constructors take a
slice of Query rather than a slice of empty interface.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/a28275ec
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/a28275ec
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/a28275ec
Branch: refs/heads/master
Commit: a28275ec8d7dd064f033afd81cfa43e3dd16d4ac
Parents: 71a17b0
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Sep 9 18:17:53 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:21:15 2015 -0700
----------------------------------------------------------------------
go/build.go | 8 ++++++++
go/lucy/search.go | 22 ++++++++++++++++++++++
2 files changed, 30 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/a28275ec/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 43957d2..67672eb 100644
--- a/go/build.go
+++ b/go/build.go
@@ -159,6 +159,14 @@ func specClasses(parcel *cfc.Parcel) {
hitsBinding.SpecMethod("", "Error() error")
hitsBinding.SetSuppressStruct(true)
hitsBinding.Register()
+
+ andQueryBinding := cfc.NewGoClass(parcel, "Lucy::Search::ANDQuery")
+ andQueryBinding.SetSuppressCtor(true)
+ andQueryBinding.Register()
+
+ orQueryBinding := cfc.NewGoClass(parcel, "Lucy::Search::ORQuery")
+ orQueryBinding.SetSuppressCtor(true)
+ orQueryBinding.Register()
}
func build() {
http://git-wip-us.apache.org/repos/asf/lucy/blob/a28275ec/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index 3335252..8d18ea9 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -22,6 +22,8 @@ package lucy
#include "Lucy/Search/IndexSearcher.h"
#include "Lucy/Search/Query.h"
#include "Lucy/Search/Searcher.h"
+#include "Lucy/Search/ANDQuery.h"
+#include "Lucy/Search/ORQuery.h"
#include "Lucy/Document/HitDoc.h"
#include "Clownfish/Hash.h"
#include "Clownfish/HashIterator.h"
@@ -161,3 +163,23 @@ func (obj *HitsIMP) Next(hit interface{}) bool {
func (obj *HitsIMP) Error() error {
return obj.err
}
+
+func NewANDQuery(children []Query) ANDQuery {
+ vec := clownfish.NewVector(len(children))
+ for _, child := range children {
+ vec.Push(child)
+ }
+ childrenC := (*C.cfish_Vector)(unsafe.Pointer(vec.TOPTR()))
+ cfObj := C.lucy_ANDQuery_new(childrenC)
+ return WRAPANDQuery(unsafe.Pointer(cfObj))
+}
+
+func NewORQuery(children []Query) ORQuery {
+ vec := clownfish.NewVector(len(children))
+ for _, child := range children {
+ vec.Push(child)
+ }
+ childrenC := (*C.cfish_Vector)(unsafe.Pointer(vec.TOPTR()))
+ cfObj := C.lucy_ORQuery_new(childrenC)
+ return WRAPORQuery(unsafe.Pointer(cfObj))
+}
[03/16] lucy git commit: Add test utility functions.
Posted by ma...@apache.org.
Add test utility functions.
Add Go versions of `createIndex`, `createSchema`.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/71a17b05
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/71a17b05
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/71a17b05
Branch: refs/heads/master
Commit: 71a17b05c10302769f335ff18103d875ac2fb255
Parents: 3d4a0b6
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 11 19:38:59 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 17:32:23 2015 -0700
----------------------------------------------------------------------
go/lucy/lucy_test.go | 43 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/71a17b05/go/lucy/lucy_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/lucy_test.go b/go/lucy/lucy_test.go
index 82ba878..c0c743e 100644
--- a/go/lucy/lucy_test.go
+++ b/go/lucy/lucy_test.go
@@ -20,8 +20,47 @@ import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
import "testing"
import "reflect"
-func TestStuff(t *testing.T) {
- NewSchema()
+type testDoc struct {
+ Content string
+}
+
+// Build a RAM index, using the supplied array of strings as source material.
+// The index will have a single field: "content".
+func createTestIndex(values ...string) Folder {
+ folder := NewRAMFolder("")
+ schema := createTestSchema()
+ indexerArgs := &OpenIndexerArgs{
+ Schema: schema,
+ Index: folder,
+ Create: true,
+ }
+ indexer, err := OpenIndexer(indexerArgs)
+ if err != nil {
+ panic(err)
+ }
+ defer indexer.Close()
+
+ for _, val := range values {
+ err := indexer.AddDoc(&testDoc{val})
+ if err != nil {
+ panic(err)
+ }
+ }
+ err = indexer.Commit()
+ if err != nil {
+ panic(err)
+ }
+
+ return folder
+}
+
+func createTestSchema() Schema {
+ schema := NewSchema()
+ analyzer := NewStandardTokenizer()
+ fieldType := NewFullTextType(analyzer)
+ fieldType.SetHighlightable(true)
+ schema.SpecField("content", fieldType)
+ return schema
}
func TestOpenIndexer(t *testing.T) {
[07/16] lucy git commit: Test Go bindings for BitVector.
Posted by ma...@apache.org.
Test Go bindings for BitVector.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b76fe6aa
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b76fe6aa
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b76fe6aa
Branch: refs/heads/master
Commit: b76fe6aadf3c74071b444d0d3728bf83ed1e63fa
Parents: 0c44c9f
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 14:23:37 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:23 2015 -0700
----------------------------------------------------------------------
go/lucy/object_test.go | 122 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 122 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/b76fe6aa/go/lucy/object_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/object_test.go b/go/lucy/object_test.go
new file mode 100644
index 0000000..51ebe83
--- /dev/null
+++ b/go/lucy/object_test.go
@@ -0,0 +1,122 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package lucy
+
+import "testing"
+import _ "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+
+func TestBitVecSingle(t *testing.T) {
+ bitVec := NewBitVector(0)
+ if bitVec.Get(31) {
+ t.Error("Get for unset bit")
+ }
+ bitVec.Set(31)
+ if !bitVec.Get(31) {
+ t.Error("Get for true bit")
+ }
+ bitVec.Clear(31)
+ if bitVec.Get(31) {
+ t.Error("Get for cleared bit")
+ }
+ bitVec.Flip(31)
+ if !bitVec.Get(31) {
+ t.Error("Get for flipped bit")
+ }
+ if hit := bitVec.NextHit(0); hit != 31 {
+ t.Error("NextHit should find hit")
+ }
+ if hit := bitVec.NextHit(32); hit != -1 {
+ t.Error("NextHit exhausted")
+ }
+}
+
+func TestBitVecMisc(t *testing.T) {
+ bitVec := NewBitVector(0)
+ oldCap := bitVec.GetCapacity()
+ bitVec.Grow(64)
+ if newCap := bitVec.GetCapacity(); newCap <= oldCap {
+ t.Error("Grow/GetCapacity had unexpected result: %v %v", oldCap, newCap)
+ }
+ bitVec.Set(0)
+ bitVec.Set(63)
+ bools := bitVec.ToArray()
+ count := 0;
+ for _, val := range bools {
+ if val {
+ count++
+ }
+ }
+ if count != 2 {
+ t.Error("ToArray yielded bad count: %d", count)
+ }
+}
+
+func TestBitVecBlock(t *testing.T) {
+ bitVec := NewBitVector(0)
+ bitVec.FlipBlock(10, 10)
+ if count := bitVec.Count(); count != 10 {
+ t.Error("FlipBlock")
+ }
+ bitVec.FlipBlock(15, 5)
+ if count := bitVec.Count(); count != 5 {
+ t.Error("FlipBlock mixed")
+ }
+ bitVec.ClearAll()
+ if count := bitVec.Count(); count != 0 {
+ t.Error("ClearAll")
+ }
+}
+
+func TestBitVecBool(t *testing.T) {
+ var dupe BitVector
+ seven := NewBitVector(0);
+ twelve := NewBitVector(0);
+ seven.FlipBlock(0, 3) // 0111
+ twelve.FlipBlock(2, 2) // 1100
+
+ dupe = seven.Clone().(BitVector)
+ dupe.And(twelve)
+ if count := dupe.Count(); count != 1 {
+ t.Errorf("And: %d", count)
+ }
+
+ dupe = seven.Clone().(BitVector)
+ dupe.Or(twelve)
+ if count := dupe.Count(); count != 4 {
+ t.Errorf("Or: %d", count)
+ }
+
+ dupe = seven.Clone().(BitVector)
+ dupe.Xor(twelve)
+ if count := dupe.Count(); count != 3 {
+ t.Errorf("Xor: %d", count)
+ }
+
+ dupe = seven.Clone().(BitVector)
+ dupe.AndNot(twelve)
+ if count := dupe.Count(); count != 2 {
+ t.Errorf("AndNot: %d", count)
+ }
+
+ dupe = seven.Clone().(BitVector)
+ dupe.Mimic(twelve)
+ if count := dupe.Count(); count != twelve.Count() {
+ t.Errorf("Mimic: %d", count)
+ }
+}
+
+
[13/16] lucy git commit: Test BitVecMatcher Go bindings.
Posted by ma...@apache.org.
Test BitVecMatcher Go bindings.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/aa8e372e
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/aa8e372e
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/aa8e372e
Branch: refs/heads/master
Commit: aa8e372efb1fd1bd21d8bde40eb7bd8088f1c22b
Parents: db2c25d
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 17:45:23 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:24 2015 -0700
----------------------------------------------------------------------
go/lucy/search_test.go | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/aa8e372e/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index c5e2cc2..e822d09 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -268,3 +268,23 @@ func TestMockMatcherBasics(t *testing.T) {
t.Error("Next (iteration finished): %d", got)
}
}
+
+func TestBitVecMatcherBasics(t *testing.T) {
+ bv := NewBitVector(0)
+ bv.Set(42)
+ bv.Set(43)
+ bv.Set(100)
+ matcher := NewBitVecMatcher(bv)
+ if got := matcher.Next(); got != 42 {
+ t.Error("Next: %d", got)
+ }
+ if got := matcher.GetDocID(); got != 42 {
+ t.Error("GetDocID: %d", got)
+ }
+ if got := matcher.Advance(50); got != 100 {
+ t.Error("Advance: %d", got)
+ }
+ if got := matcher.Next(); got != 0 {
+ t.Error("Next (iteration finished): %d", got)
+ }
+}
[16/16] lucy git commit: Merge branch 'LUCY-282-refine-go-pt1'
Posted by ma...@apache.org.
Merge branch 'LUCY-282-refine-go-pt1'
Refine Go bindings and add tests for many search classes, especially the
Query classes.
Also fix argument handling for OpenIndexer and OpenIndexSearcher.
This closes #19.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/79a77691
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/79a77691
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/79a77691
Branch: refs/heads/master
Commit: 79a776911fac917d6ee1a70fcf9166112252e60e
Parents: c94acc5 055407f
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Fri Sep 11 14:55:10 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Fri Sep 11 14:56:23 2015 -0700
----------------------------------------------------------------------
core/Lucy/Search/ANDMatcher.cfh | 4 +-
core/Lucy/Search/ORMatcher.cfh | 4 +-
core/Lucy/Search/PolyMatcher.cfh | 4 +-
core/Lucy/Search/RequiredOptionalMatcher.cfh | 4 +-
core/LucyX/Search/MockMatcher.c | 6 +
go/build.go | 28 ++
go/lucy/index.go | 22 +-
go/lucy/lucy.go | 1 +
go/lucy/lucy_test.go | 43 ++-
go/lucy/object.go | 51 ++++
go/lucy/object_test.go | 131 +++++++++
go/lucy/search.go | 91 +++++-
go/lucy/search_test.go | 321 ++++++++++++++++++++++
13 files changed, 675 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
[15/16] lucy git commit: Test Go bindings for Boolean matchers.
Posted by ma...@apache.org.
Test Go bindings for Boolean matchers.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/055407fc
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/055407fc
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/055407fc
Branch: refs/heads/master
Commit: 055407fccdd4739cb3e840e422ef43e3cff16bc3
Parents: 9cd103c
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 20:36:52 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:58:22 2015 -0700
----------------------------------------------------------------------
go/lucy/search_test.go | 63 +++++++++++++++++++++++++++++++++------------
1 file changed, 47 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/055407fc/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index e822d09..492ab1f 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -250,16 +250,17 @@ func TestLeafQueryBasics(t *testing.T) {
checkQueryToStringHasFoo(t, query)
}
-func TestMockMatcherBasics(t *testing.T) {
- matcher := newMockMatcher([]int32{42, 43, 100}, []float32{1.5, 1.5, 1.5})
+func checkMatcher(t *testing.T, matcher Matcher, supportsScore bool) {
if got := matcher.Next(); got != 42 {
t.Error("Next: %d", got)
}
if got := matcher.GetDocID(); got != 42 {
t.Error("GetDocID: %d", got)
}
- if score := matcher.Score(); score != 1.5 {
- t.Error("Score: %f", score)
+ if supportsScore {
+ if score := matcher.Score(); score != 2 {
+ t.Error("Score: %f", score)
+ }
}
if got := matcher.Advance(50); got != 100 {
t.Error("Advance: %d", got)
@@ -269,22 +270,52 @@ func TestMockMatcherBasics(t *testing.T) {
}
}
+func TestMockMatcherBasics(t *testing.T) {
+ matcher := newMockMatcher([]int32{42, 43, 100}, []float32{2,2,2})
+ checkMatcher(t, matcher, true)
+}
+
func TestBitVecMatcherBasics(t *testing.T) {
bv := NewBitVector(0)
bv.Set(42)
bv.Set(43)
bv.Set(100)
matcher := NewBitVecMatcher(bv)
- if got := matcher.Next(); got != 42 {
- t.Error("Next: %d", got)
- }
- if got := matcher.GetDocID(); got != 42 {
- t.Error("GetDocID: %d", got)
- }
- if got := matcher.Advance(50); got != 100 {
- t.Error("Advance: %d", got)
- }
- if got := matcher.Next(); got != 0 {
- t.Error("Next (iteration finished): %d", got)
- }
+ checkMatcher(t, matcher, false)
+}
+
+func TestANDMatcherBasics(t *testing.T) {
+ a := newMockMatcher([]int32{42, 43, 99, 100}, []float32{1,1,1,1})
+ b := newMockMatcher([]int32{1, 42, 43, 100}, []float32{1,1,1,1})
+ matcher := NewANDMatcher([]Matcher{a, b}, nil)
+ checkMatcher(t, matcher, true)
+}
+
+func TestORMatcherBasics(t *testing.T) {
+ a := newMockMatcher([]int32{42, 43}, nil)
+ b := newMockMatcher([]int32{42, 100}, nil)
+ matcher := NewORMatcher([]Matcher{a, b})
+ checkMatcher(t, matcher, false)
+}
+
+func TestORScorerBasics(t *testing.T) {
+ a := newMockMatcher([]int32{42, 43}, []float32{1,1})
+ b := newMockMatcher([]int32{42, 100}, []float32{1,1})
+ matcher := NewORScorer([]Matcher{a, b}, nil)
+ checkMatcher(t, matcher, true)
+}
+
+func TestReqOptMatcherBasics(t *testing.T) {
+ req := newMockMatcher([]int32{42, 43, 100}, []float32{1,1,1})
+ opt := newMockMatcher([]int32{1, 42, 99, 100}, []float32{1,1,1,1})
+ matcher := NewRequiredOptionalMatcher(nil, req, opt)
+ checkMatcher(t, matcher, true)
+}
+
+func TestNOTMatcherBasics(t *testing.T) {
+ a := newMockMatcher([]int32{1, 42, 43, 99, 100}, nil)
+ b := newMockMatcher([]int32{1, 99}, nil)
+ notB := NewNOTMatcher(b, 999)
+ matcher := NewANDMatcher([]Matcher{a, notB}, nil)
+ checkMatcher(t, matcher, false)
}
[06/16] lucy git commit: MockMatcher Go ctor binding.
Posted by ma...@apache.org.
MockMatcher Go ctor binding.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/a7aa7791
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/a7aa7791
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/a7aa7791
Branch: refs/heads/master
Commit: a7aa779141065a2964a70357d746522ae231d0aa
Parents: 2b8b632
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 16:58:36 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:23 2015 -0700
----------------------------------------------------------------------
go/build.go | 4 ++++
go/lucy/search.go | 25 +++++++++++++++++++++++++
go/lucy/search_test.go | 19 +++++++++++++++++++
3 files changed, 48 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/a7aa7791/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 828a79b..5c84645 100644
--- a/go/build.go
+++ b/go/build.go
@@ -171,6 +171,10 @@ func specClasses(parcel *cfc.Parcel) {
bitVecBinding := cfc.NewGoClass(parcel, "Lucy::Object::BitVector")
bitVecBinding.SpecMethod("To_Array", "ToArray() []bool")
bitVecBinding.Register()
+
+ mockMatcherBinding := cfc.NewGoClass(parcel, "LucyX::Search::MockMatcher")
+ mockMatcherBinding.SetSuppressCtor(true)
+ mockMatcherBinding.Register()
}
func build() {
http://git-wip-us.apache.org/repos/asf/lucy/blob/a7aa7791/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index 8d18ea9..0c8dbb2 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -25,8 +25,16 @@ package lucy
#include "Lucy/Search/ANDQuery.h"
#include "Lucy/Search/ORQuery.h"
#include "Lucy/Document/HitDoc.h"
+#include "LucyX/Search/MockMatcher.h"
+#include "Clownfish/Blob.h"
#include "Clownfish/Hash.h"
#include "Clownfish/HashIterator.h"
+
+static inline void
+float32_set(float *floats, size_t i, float value) {
+ floats[i] = value;
+}
+
*/
import "C"
import "fmt"
@@ -183,3 +191,20 @@ func NewORQuery(children []Query) ORQuery {
cfObj := C.lucy_ORQuery_new(childrenC)
return WRAPORQuery(unsafe.Pointer(cfObj))
}
+
+func newMockMatcher(docIDs []int32, scores []float32) MockMatcher {
+ docIDsconv := NewI32Array(docIDs)
+ docIDsCF := (*C.lucy_I32Array)(unsafe.Pointer(docIDsconv.TOPTR()))
+ var blob *C.cfish_Blob = nil
+ if scores != nil {
+ size := len(scores) * 4
+ floats := (*C.float)(C.malloc(C.size_t(size)))
+ for i := 0; i < len(scores); i++ {
+ C.float32_set(floats, C.size_t(i), C.float(scores[i]))
+ }
+ blob = C.cfish_Blob_new_steal((*C.char)(unsafe.Pointer(floats)), C.size_t(size))
+ defer C.cfish_decref(unsafe.Pointer(blob))
+ }
+ matcher := C.lucy_MockMatcher_new(docIDsCF, blob)
+ return WRAPMockMatcher(unsafe.Pointer(matcher))
+}
http://git-wip-us.apache.org/repos/asf/lucy/blob/a7aa7791/go/lucy/search_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/search_test.go b/go/lucy/search_test.go
index d566553..c5e2cc2 100644
--- a/go/lucy/search_test.go
+++ b/go/lucy/search_test.go
@@ -249,3 +249,22 @@ func TestLeafQueryBasics(t *testing.T) {
checkQueryEquals(t, query)
checkQueryToStringHasFoo(t, query)
}
+
+func TestMockMatcherBasics(t *testing.T) {
+ matcher := newMockMatcher([]int32{42, 43, 100}, []float32{1.5, 1.5, 1.5})
+ if got := matcher.Next(); got != 42 {
+ t.Error("Next: %d", got)
+ }
+ if got := matcher.GetDocID(); got != 42 {
+ t.Error("GetDocID: %d", got)
+ }
+ if score := matcher.Score(); score != 1.5 {
+ t.Error("Score: %f", score)
+ }
+ if got := matcher.Advance(50); got != 100 {
+ t.Error("Advance: %d", got)
+ }
+ if got := matcher.Next(); got != 0 {
+ t.Error("Next (iteration finished): %d", got)
+ }
+}
[14/16] lucy git commit: Make PolyMatcher ctor bindings take
[]Matcher.
Posted by ma...@apache.org.
Make PolyMatcher ctor bindings take []Matcher.
Make ANDMatcher, ORMatcher, and ORScorer constructors take a slice of
Matcher rather than a slice of empty interface.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/9cd103c7
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/9cd103c7
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/9cd103c7
Branch: refs/heads/master
Commit: 9cd103c7dfafa7153480789cb28618e4555abebd
Parents: aaf6abb
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Sep 9 18:55:21 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:58:22 2015 -0700
----------------------------------------------------------------------
go/build.go | 12 ++++++++++++
go/lucy/search.go | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/9cd103c7/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 5c84645..7596f7b 100644
--- a/go/build.go
+++ b/go/build.go
@@ -168,6 +168,18 @@ func specClasses(parcel *cfc.Parcel) {
orQueryBinding.SetSuppressCtor(true)
orQueryBinding.Register()
+ andMatcherBinding := cfc.NewGoClass(parcel, "Lucy::Search::ANDMatcher")
+ andMatcherBinding.SetSuppressCtor(true)
+ andMatcherBinding.Register()
+
+ orMatcherBinding := cfc.NewGoClass(parcel, "Lucy::Search::ORMatcher")
+ orMatcherBinding.SetSuppressCtor(true)
+ orMatcherBinding.Register()
+
+ orScorerBinding := cfc.NewGoClass(parcel, "Lucy::Search::ORScorer")
+ orScorerBinding.SetSuppressCtor(true)
+ orScorerBinding.Register()
+
bitVecBinding := cfc.NewGoClass(parcel, "Lucy::Object::BitVector")
bitVecBinding.SpecMethod("To_Array", "ToArray() []bool")
bitVecBinding.Register()
http://git-wip-us.apache.org/repos/asf/lucy/blob/9cd103c7/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index 0c8dbb2..2785d51 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -24,6 +24,8 @@ package lucy
#include "Lucy/Search/Searcher.h"
#include "Lucy/Search/ANDQuery.h"
#include "Lucy/Search/ORQuery.h"
+#include "Lucy/Search/ANDMatcher.h"
+#include "Lucy/Search/ORMatcher.h"
#include "Lucy/Document/HitDoc.h"
#include "LucyX/Search/MockMatcher.h"
#include "Clownfish/Blob.h"
@@ -192,6 +194,38 @@ func NewORQuery(children []Query) ORQuery {
return WRAPORQuery(unsafe.Pointer(cfObj))
}
+func NewANDMatcher(children []Matcher, sim Similarity) ANDMatcher {
+ simC := (*C.lucy_Similarity)(clownfish.UnwrapNullable(sim))
+ vec := clownfish.NewVector(len(children))
+ for _, child := range children {
+ vec.Push(child)
+ }
+ childrenC := (*C.cfish_Vector)(unsafe.Pointer(vec.TOPTR()))
+ cfObj := C.lucy_ANDMatcher_new(childrenC, simC)
+ return WRAPANDMatcher(unsafe.Pointer(cfObj))
+}
+
+func NewORMatcher(children []Matcher) ORMatcher {
+ vec := clownfish.NewVector(len(children))
+ for _, child := range children {
+ vec.Push(child)
+ }
+ childrenC := (*C.cfish_Vector)(unsafe.Pointer(vec.TOPTR()))
+ cfObj := C.lucy_ORMatcher_new(childrenC)
+ return WRAPORMatcher(unsafe.Pointer(cfObj))
+}
+
+func NewORScorer(children []Matcher, sim Similarity) ORScorer {
+ simC := (*C.lucy_Similarity)(clownfish.UnwrapNullable(sim))
+ vec := clownfish.NewVector(len(children))
+ for _, child := range children {
+ vec.Push(child)
+ }
+ childrenC := (*C.cfish_Vector)(unsafe.Pointer(vec.TOPTR()))
+ cfObj := C.lucy_ORScorer_new(childrenC, simC)
+ return WRAPORScorer(unsafe.Pointer(cfObj))
+}
+
func newMockMatcher(docIDs []int32, scores []float32) MockMatcher {
docIDsconv := NewI32Array(docIDs)
docIDsCF := (*C.lucy_I32Array)(unsafe.Pointer(docIDsconv.TOPTR()))
[02/16] lucy git commit: Support Folder as arg for IndexSearcher,
Indexer.
Posted by ma...@apache.org.
Support Folder as arg for IndexSearcher, Indexer.
OpenIndexer and OpenIndexSearcher should accept either a Go `string`
path or a Clownfish Folder as the `index` argument.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b69adb89
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b69adb89
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b69adb89
Branch: refs/heads/master
Commit: b69adb89aa9fc6a9c7d97c2729a9a0ceadc103be
Parents: c94acc5
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Tue Aug 11 13:07:02 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 16:17:59 2015 -0700
----------------------------------------------------------------------
go/lucy/index.go | 22 +++++-----------------
go/lucy/search.go | 10 ++--------
2 files changed, 7 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/b69adb89/go/lucy/index.go
----------------------------------------------------------------------
diff --git a/go/lucy/index.go b/go/lucy/index.go
index a55771e..4aab0a2 100644
--- a/go/lucy/index.go
+++ b/go/lucy/index.go
@@ -47,20 +47,10 @@ type OpenIndexerArgs struct {
}
func OpenIndexer(args *OpenIndexerArgs) (obj Indexer, err error) {
- var schemaC *C.lucy_Schema = nil
- if args.Schema != nil {
- schemaC = (*C.lucy_Schema)(unsafe.Pointer(args.Schema.TOPTR()))
- }
- switch args.Index.(type) {
- case string:
- default:
- panic("TODO: support Folder")
- }
- ixLoc := clownfish.NewString(args.Index.(string))
- var managerC *C.lucy_IndexManager = nil
- if args.Manager != nil {
- managerC = (*C.lucy_IndexManager)(unsafe.Pointer(args.Manager.TOPTR()))
- }
+ schema := (*C.lucy_Schema)(clownfish.UnwrapNullable(args.Schema))
+ manager := (*C.lucy_IndexManager)(clownfish.UnwrapNullable(args.Manager))
+ index := (*C.cfish_Obj)(clownfish.GoToClownfish(args.Index, unsafe.Pointer(C.CFISH_OBJ), false))
+ defer C.cfish_decref(unsafe.Pointer(index))
var flags int32
if args.Create {
flags = flags | int32(C.lucy_Indexer_CREATE)
@@ -69,9 +59,7 @@ func OpenIndexer(args *OpenIndexerArgs) (obj Indexer, err error) {
flags = flags | int32(C.lucy_Indexer_TRUNCATE)
}
err = clownfish.TrapErr(func() {
- cfObj := C.lucy_Indexer_new(schemaC,
- (*C.cfish_Obj)(unsafe.Pointer(ixLoc.TOPTR())),
- managerC, C.int32_t(flags))
+ cfObj := C.lucy_Indexer_new(schema, index, manager, C.int32_t(flags))
obj = WRAPIndexer(unsafe.Pointer(cfObj))
})
return obj, err
http://git-wip-us.apache.org/repos/asf/lucy/blob/b69adb89/go/lucy/search.go
----------------------------------------------------------------------
diff --git a/go/lucy/search.go b/go/lucy/search.go
index c71048b..3335252 100644
--- a/go/lucy/search.go
+++ b/go/lucy/search.go
@@ -40,14 +40,8 @@ type HitsIMP struct {
}
func OpenIndexSearcher(index interface{}) (obj IndexSearcher, err error) {
- var indexC *C.cfish_Obj
- switch index.(type) {
- case string:
- ixLoc := clownfish.NewString(index.(string))
- indexC = (*C.cfish_Obj)(unsafe.Pointer(ixLoc.TOPTR()))
- default:
- panic("TODO: support Folder")
- }
+ indexC := (*C.cfish_Obj)(clownfish.GoToClownfish(index, unsafe.Pointer(C.CFISH_OBJ), false))
+ defer C.cfish_decref(unsafe.Pointer(indexC))
err = clownfish.TrapErr(func() {
cfObj := C.lucy_IxSearcher_new(indexC)
obj = WRAPIndexSearcher(unsafe.Pointer(cfObj))
[12/16] lucy git commit: Make `similarity` arg optional.
Posted by ma...@apache.org.
Make `similarity` arg optional.
PolyMatchers already deal with NULL similarity correctly, so make it
officially optional.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/aaf6abbe
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/aaf6abbe
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/aaf6abbe
Branch: refs/heads/master
Commit: aaf6abbe9909648b157dbaaabb1e84c71f47cb5a
Parents: aa8e372
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 20:05:34 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:24 2015 -0700
----------------------------------------------------------------------
core/Lucy/Search/ANDMatcher.cfh | 4 ++--
core/Lucy/Search/ORMatcher.cfh | 4 ++--
core/Lucy/Search/PolyMatcher.cfh | 4 ++--
core/Lucy/Search/RequiredOptionalMatcher.cfh | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/aaf6abbe/core/Lucy/Search/ANDMatcher.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/ANDMatcher.cfh b/core/Lucy/Search/ANDMatcher.cfh
index 3e624c7..00e9cec 100644
--- a/core/Lucy/Search/ANDMatcher.cfh
+++ b/core/Lucy/Search/ANDMatcher.cfh
@@ -26,10 +26,10 @@ class Lucy::Search::ANDMatcher inherits Lucy::Search::PolyMatcher {
bool first_time;
inert incremented ANDMatcher*
- new(Vector *children, Similarity *sim);
+ new(Vector *children, Similarity *sim = NULL);
inert ANDMatcher*
- init(ANDMatcher *self, Vector *children, Similarity *similarity);
+ init(ANDMatcher *self, Vector *children, Similarity *similarity = NULL);
public void
Destroy(ANDMatcher *self);
http://git-wip-us.apache.org/repos/asf/lucy/blob/aaf6abbe/core/Lucy/Search/ORMatcher.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/ORMatcher.cfh b/core/Lucy/Search/ORMatcher.cfh
index 89aaab9..97fcc0d 100644
--- a/core/Lucy/Search/ORMatcher.cfh
+++ b/core/Lucy/Search/ORMatcher.cfh
@@ -79,10 +79,10 @@ class Lucy::Search::ORScorer inherits Lucy::Search::ORMatcher {
int32_t doc_id;
inert incremented ORScorer*
- new(Vector *children, Similarity *similarity);
+ new(Vector *children, Similarity *similarity = NULL);
inert ORScorer*
- init(ORScorer *self, Vector *children, Similarity *similarity);
+ init(ORScorer *self, Vector *children, Similarity *similarity = NULL);
public void
Destroy(ORScorer *self);
http://git-wip-us.apache.org/repos/asf/lucy/blob/aaf6abbe/core/Lucy/Search/PolyMatcher.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/PolyMatcher.cfh b/core/Lucy/Search/PolyMatcher.cfh
index 9b9c9c8..d3e27cb 100644
--- a/core/Lucy/Search/PolyMatcher.cfh
+++ b/core/Lucy/Search/PolyMatcher.cfh
@@ -28,10 +28,10 @@ class Lucy::Search::PolyMatcher inherits Lucy::Search::Matcher {
float *coord_factors;
inert incremented PolyMatcher*
- new(Vector *children, Similarity *similarity);
+ new(Vector *children, Similarity *similarity = NULL);
inert PolyMatcher*
- init(PolyMatcher *self, Vector *children, Similarity *similarity);
+ init(PolyMatcher *self, Vector *children, Similarity *similarity = NULL);
public void
Destroy(PolyMatcher *self);
http://git-wip-us.apache.org/repos/asf/lucy/blob/aaf6abbe/core/Lucy/Search/RequiredOptionalMatcher.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Search/RequiredOptionalMatcher.cfh b/core/Lucy/Search/RequiredOptionalMatcher.cfh
index 4a86d93..be5a82a 100644
--- a/core/Lucy/Search/RequiredOptionalMatcher.cfh
+++ b/core/Lucy/Search/RequiredOptionalMatcher.cfh
@@ -27,11 +27,11 @@ class Lucy::Search::RequiredOptionalMatcher nickname ReqOptMatcher
bool opt_matcher_first_time;
inert incremented RequiredOptionalMatcher*
- new(Similarity *similarity, Matcher *required_matcher,
+ new(Similarity *similarity = NULL, Matcher *required_matcher,
Matcher *optional_matcher = NULL);
inert RequiredOptionalMatcher*
- init(RequiredOptionalMatcher *self, Similarity *similarity,
+ init(RequiredOptionalMatcher *self, Similarity *similarity = NULL,
Matcher *required_matcher, Matcher *optional_matcher = NULL);
public void
[09/16] lucy git commit: I32Array Go ctor binding.
Posted by ma...@apache.org.
I32Array Go ctor binding.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/2b8b6323
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/2b8b6323
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/2b8b6323
Branch: refs/heads/master
Commit: 2b8b63236b2854b344cdba725f7ac6b60d844644
Parents: 456a825
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 16:58:06 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:23 2015 -0700
----------------------------------------------------------------------
go/lucy/object.go | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/2b8b6323/go/lucy/object.go
----------------------------------------------------------------------
diff --git a/go/lucy/object.go b/go/lucy/object.go
index 0dc669f..78c86f5 100644
--- a/go/lucy/object.go
+++ b/go/lucy/object.go
@@ -18,11 +18,13 @@ package lucy
/*
#include "Lucy/Object/BitVector.h"
+#include "Lucy/Object/I32Array.h"
*/
import "C"
import "fmt"
+import "unsafe"
-import _ "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+import "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
func (bv *BitVectorIMP) ToArray() []bool {
cap := bv.GetCapacity()
@@ -36,3 +38,14 @@ func (bv *BitVectorIMP) ToArray() []bool {
return bools
}
+func NewI32Array(nums []int32) I32Array {
+ size := len(nums)
+ if int(C.uint32_t(size)) != size {
+ panic(clownfish.NewErr("input too large"))
+ }
+ obj := C.lucy_I32Arr_new_blank(C.uint32_t(size))
+ for i := 0; i < size; i++ {
+ C.LUCY_I32Arr_Set(obj, C.uint32_t(i), C.int32_t(nums[i]))
+ }
+ return WRAPI32Array(unsafe.Pointer(obj))
+}
[08/16] lucy git commit: Custom Go binding for `BitVec_To_Array`.
Posted by ma...@apache.org.
Custom Go binding for `BitVec_To_Array`.
Return a slice of bool.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/0c44c9f5
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/0c44c9f5
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/0c44c9f5
Branch: refs/heads/master
Commit: 0c44c9f505cd500d3f784b28c6c346a5f9c1396e
Parents: c0bdb9c
Author: Marvin Humphrey <ma...@rectangular.com>
Authored: Wed Aug 12 14:22:08 2015 -0700
Committer: Marvin Humphrey <ma...@rectangular.com>
Committed: Wed Sep 9 18:25:23 2015 -0700
----------------------------------------------------------------------
go/build.go | 4 ++++
go/lucy/object.go | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/0c44c9f5/go/build.go
----------------------------------------------------------------------
diff --git a/go/build.go b/go/build.go
index 67672eb..828a79b 100644
--- a/go/build.go
+++ b/go/build.go
@@ -167,6 +167,10 @@ func specClasses(parcel *cfc.Parcel) {
orQueryBinding := cfc.NewGoClass(parcel, "Lucy::Search::ORQuery")
orQueryBinding.SetSuppressCtor(true)
orQueryBinding.Register()
+
+ bitVecBinding := cfc.NewGoClass(parcel, "Lucy::Object::BitVector")
+ bitVecBinding.SpecMethod("To_Array", "ToArray() []bool")
+ bitVecBinding.Register()
}
func build() {
http://git-wip-us.apache.org/repos/asf/lucy/blob/0c44c9f5/go/lucy/object.go
----------------------------------------------------------------------
diff --git a/go/lucy/object.go b/go/lucy/object.go
new file mode 100644
index 0000000..0dc669f
--- /dev/null
+++ b/go/lucy/object.go
@@ -0,0 +1,38 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package lucy
+
+/*
+#include "Lucy/Object/BitVector.h"
+*/
+import "C"
+import "fmt"
+
+import _ "git-wip-us.apache.org/repos/asf/lucy-clownfish.git/runtime/go/clownfish"
+
+func (bv *BitVectorIMP) ToArray() []bool {
+ cap := bv.GetCapacity()
+ if cap != uint32(int(cap)) {
+ panic(fmt.Sprintf("Capacity of range: %d", cap))
+ }
+ bools := make([]bool, int(cap))
+ for i := uint32(0); i < cap; i++ {
+ bools[i] = bv.Get(i)
+ }
+ return bools
+}
+