You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/08/06 18:22:19 UTC
[3/5] lucy git commit: Implement Doc_Field_Names
Implement Doc_Field_Names
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/f1c30213
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/f1c30213
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/f1c30213
Branch: refs/heads/master
Commit: f1c30213afc3b2d9b1838ce662a127f0004ed5d8
Parents: 78a8299
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 1 17:22:18 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Wed Aug 5 15:26:15 2015 +0200
----------------------------------------------------------------------
c/src/Lucy/Document/Doc.c | 7 +++++++
core/Lucy/Document/Doc.cfh | 5 +++++
go/cfext/lucy.c | 7 +++++++
go/lucy/lucy.go | 12 ++++++++++++
perl/xs/Lucy/Document/Doc.c | 20 ++++++++++++++++++++
5 files changed, 51 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/f1c30213/c/src/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Document/Doc.c b/c/src/Lucy/Document/Doc.c
index 717059f..d0fb065 100644
--- a/c/src/Lucy/Document/Doc.c
+++ b/c/src/Lucy/Document/Doc.c
@@ -23,6 +23,7 @@
#include "Clownfish/Err.h"
#include "Clownfish/Hash.h"
#include "Clownfish/Class.h"
+#include "Clownfish/Vector.h"
#include "Lucy/Store/InStream.h"
#include "Lucy/Store/OutStream.h"
#include "Lucy/Util/Freezer.h"
@@ -85,6 +86,12 @@ Doc_Extract_IMP(Doc *self, String *field) {
return INCREF(Hash_Fetch(hash, field));
}
+Vector*
+Doc_Field_Names_IMP(Doc *self) {
+ Hash *hash = (Hash*)Doc_IVARS(self)->fields;
+ return Hash_Keys(hash);
+}
+
Hash*
Doc_Dump_IMP(Doc *self) {
UNUSED_VAR(self);
http://git-wip-us.apache.org/repos/asf/lucy/blob/f1c30213/core/Lucy/Document/Doc.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Document/Doc.cfh b/core/Lucy/Document/Doc.cfh
index d30a6b3..c1da681 100644
--- a/core/Lucy/Document/Doc.cfh
+++ b/core/Lucy/Document/Doc.cfh
@@ -76,6 +76,11 @@ public class Lucy::Document::Doc inherits Clownfish::Obj {
nullable incremented Obj*
Extract(Doc *self, String *field);
+ /** Return a list of names of all fields present.
+ */
+ incremented Vector*
+ Field_Names(Doc *self);
+
/* Unimplemented methods.
*/
public bool
http://git-wip-us.apache.org/repos/asf/lucy/blob/f1c30213/go/cfext/lucy.c
----------------------------------------------------------------------
diff --git a/go/cfext/lucy.c b/go/cfext/lucy.c
index 9e9b840..fc2df3b 100644
--- a/go/cfext/lucy.c
+++ b/go/cfext/lucy.c
@@ -135,6 +135,13 @@ Doc_Extract_IMP(Doc *self, String *field) {
return GOLUCY_Doc_Extract_BRIDGE(self, field);
}
+Doc_Field_Names_t GOLUCY_Doc_Field_Names_BRIDGE;
+
+Vector*
+Doc_Field_Names_IMP(Doc *self) {
+ return GOLUCY_Doc_Field_Names_BRIDGE(self);
+}
+
Hash*
Doc_Dump_IMP(Doc *self) {
UNUSED_VAR(self);
http://git-wip-us.apache.org/repos/asf/lucy/blob/f1c30213/go/lucy/lucy.go
----------------------------------------------------------------------
diff --git a/go/lucy/lucy.go b/go/lucy/lucy.go
index bc2e9f8..fcddfbd 100644
--- a/go/lucy/lucy.go
+++ b/go/lucy/lucy.go
@@ -95,6 +95,10 @@ extern cfish_Obj*
GOLUCY_Doc_Extract(lucy_Doc *self, cfish_String *field);
extern cfish_Obj*
(*GOLUCY_Doc_Extract_BRIDGE)(lucy_Doc *self, cfish_String *field);
+extern cfish_Vector*
+GOLUCY_Doc_Field_Names(lucy_Doc *self);
+extern cfish_Vector*
+(*GOLUCY_Doc_Field_Names_BRIDGE)(lucy_Doc *self);
extern bool
GOLUCY_Doc_Equals(lucy_Doc *self, cfish_Obj *other);
extern bool
@@ -132,6 +136,7 @@ GOLUCY_glue_exported_symbols() {
GOLUCY_Doc_Serialize_BRIDGE = GOLUCY_Doc_Serialize;
GOLUCY_Doc_Deserialize_BRIDGE = GOLUCY_Doc_Deserialize;
GOLUCY_Doc_Extract_BRIDGE = GOLUCY_Doc_Extract;
+ GOLUCY_Doc_Field_Names_BRIDGE = GOLUCY_Doc_Field_Names;
GOLUCY_Doc_Equals_BRIDGE = GOLUCY_Doc_Equals;
GOLUCY_Doc_Destroy_BRIDGE = GOLUCY_Doc_Destroy;
GOLUCY_DefDocReader_Fetch_Doc_BRIDGE = GOLUCY_DefDocReader_Fetch_Doc;
@@ -306,6 +311,13 @@ func GOLUCY_Doc_Extract(d *C.lucy_Doc, field *C.cfish_String) *C.cfish_Obj {
return C.cfish_inc_refcount(unsafe.Pointer(val))
}
+//export GOLUCY_Doc_Field_Names
+func GOLUCY_Doc_Field_Names(d *C.lucy_Doc) *C.cfish_Vector {
+ ivars := C.lucy_Doc_IVARS(d)
+ hash := (*C.cfish_Hash)(ivars.fields)
+ return C.CFISH_Hash_Keys(hash)
+}
+
//export GOLUCY_Doc_Equals
func GOLUCY_Doc_Equals(d *C.lucy_Doc, other *C.cfish_Obj) C.bool {
twin := (*C.lucy_Doc)(unsafe.Pointer(other))
http://git-wip-us.apache.org/repos/asf/lucy/blob/f1c30213/perl/xs/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Document/Doc.c b/perl/xs/Lucy/Document/Doc.c
index fff4e62..c352f4e 100644
--- a/perl/xs/Lucy/Document/Doc.c
+++ b/perl/xs/Lucy/Document/Doc.c
@@ -159,6 +159,26 @@ LUCY_Doc_Extract_IMP(lucy_Doc *self, cfish_String *field) {
return retval;
}
+cfish_Vector*
+LUCY_Doc_Field_Names_IMP(lucy_Doc *self) {
+ dTHX;
+ lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
+
+ HV *fields = (HV*)ivars->fields;
+ I32 num_fields = hv_iterinit(fields);
+ cfish_Vector *retval = cfish_Vec_new(num_fields);
+
+ while (num_fields--) {
+ HE *entry = hv_iternext(fields);
+ STRLEN key_size;
+ const char *key = XSBind_hash_key_to_utf8(aTHX_ entry, &key_size);
+ cfish_String *key_str = cfish_Str_new_from_trusted_utf8(key, key_size);
+ CFISH_Vec_Push(retval, (cfish_Obj*)key_str);
+ }
+
+ return retval;
+}
+
cfish_Hash*
LUCY_Doc_Dump_IMP(lucy_Doc *self) {
dTHX;