lucene-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r178883 - in /incubator/lucene4c/branches/gcj-backend: include/lcn_document.h include/lcn_error.h src/cmdline/main.c src/document/document.cxx
Date Sat, 28 May 2005 19:40:10 GMT
Author: rooneg
Date: Sat May 28 12:40:09 2005
New Revision: 178883

URL: http://svn.apache.org/viewcvs?rev=178883&view=rev
Log:
Finish fixing up the command line tool by adding the ability to get
fields from a document.

* src/cmdline/main.c
  (print_doc_field): implement.

* include/lcn_document.h
  (lcn_document_get_field_by_name): new declaration.

* src/document/document.cxx
  (document_get_field_by_name_baton): new struct.
  (document_get_field_by_name_internal): underlying implementation for
   lcn_document_get_field_by_name.
  (lcn_document_get_field_by_name): implement.

* include/lcn_error.h
  (LCN_ERR_NOT_FOUND): new error.

Modified:
    incubator/lucene4c/branches/gcj-backend/include/lcn_document.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_error.h
    incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c
    incubator/lucene4c/branches/gcj-backend/src/document/document.cxx

Modified: incubator/lucene4c/branches/gcj-backend/include/lcn_document.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_document.h?rev=178883&r1=178882&r2=178883&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_document.h (original)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_document.h Sat May 28 12:40:09 2005
@@ -39,6 +39,12 @@
 lcn_error_t *
 lcn_document_add_field (lcn_document_t *doc, lcn_field_t *field);
 
+lcn_error_t *
+lcn_document_get_field_by_name (lcn_field_t **field,
+                                lcn_document_t *doc,
+                                const char *fieldname,
+                                apr_pool_t *pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: incubator/lucene4c/branches/gcj-backend/include/lcn_error.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_error.h?rev=178883&r1=178882&r2=178883&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_error.h (original)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_error.h Sat May 28 12:40:09 2005
@@ -27,7 +27,8 @@
 typedef enum {
   LCN_ERR_RUNTIME_EXCEPTION,
   LCN_ERR_IO_EXCEPTION,
-  LCN_ERR_ILLEGAL_ARGUMENT_EXCEPTION
+  LCN_ERR_ILLEGAL_ARGUMENT_EXCEPTION,
+  LCN_ERR_NOT_FOUND
 } lcn_error_code_t;
 
 /** The best kind of @c lcn_error_t. */

Modified: incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c?rev=178883&r1=178882&r2=178883&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c (original)
+++ incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c Sat May 28 12:40:09 2005
@@ -47,7 +47,14 @@
                  const char *fieldname,
                  apr_pool_t *pool)
 {
-  printf ("if i had finished this code, i'd print a field now...\n");
+  lcn_field_t *field;
+  char *content;
+
+  LCN_ERR (lcn_document_get_field_by_name (&field, doc, fieldname, pool));
+
+  LCN_ERR (lcn_field_content (&content, field, pool));
+
+  printf ("%s\n", content);
 
   return LCN_NO_ERROR;
 }

Modified: incubator/lucene4c/branches/gcj-backend/src/document/document.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/document/document.cxx?rev=178883&r1=178882&r2=178883&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/document/document.cxx (original)
+++ incubator/lucene4c/branches/gcj-backend/src/document/document.cxx Sat May 28 12:40:09
2005
@@ -80,4 +80,47 @@
   return lcn__swallow_exception (document_add_field_internal, &dafb);
 }
 
+struct document_get_field_by_name_baton {
+  lcn_field_t **field;
+  lcn_document_t *doc;
+  const char *fieldname;
+  apr_pool_t *pool;
+};
+
+static void
+document_get_field_by_name_internal (void *b)
+{
+  document_get_field_by_name_baton *bat =
+    static_cast<document_get_field_by_name_baton *>(b);
+
+  *bat->field = static_cast<lcn_field_t *>(apr_palloc (bat->pool,
+                                                       sizeof (lcn_field_t)));
+
+  jstring fieldname = JvNewStringUTF (bat->fieldname);
+
+  (*bat->field)->impl = bat->doc->impl->getField (fieldname);
+}
+
+lcn_error_t *
+lcn_document_get_field_by_name (lcn_field_t **field,
+                                lcn_document_t *doc,
+                                const char *fieldname,
+                                apr_pool_t *pool)
+{
+  document_get_field_by_name_baton bat;
+
+  bat.field = field;
+  bat.doc = doc;
+  bat.fieldname = fieldname;
+  bat.pool = pool;
+
+  lcn_error_t *err =
+    lcn__swallow_exception (document_get_field_by_name_internal, &bat);
+
+  if (! err && *bat.field == NULL)
+    return lcn_error_create (LCN_ERR_NOT_FOUND, "field not found in document");
+
+  return err;
+}
+
 } // extern "C"



Mime
View raw message