lucene-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r201822 - in /incubator/lucene4c/trunk: include/lcn_field.h src/cmdline/main.c src/document/field.cxx
Date Sun, 26 Jun 2005 09:59:29 GMT
Author: rooneg
Date: Sat Jun 25 20:35:13 2005
New Revision: 201822

URL: http://svn.apache.org/viewcvs?rev=201822&view=rev
Log:
Add functions for creating keyword and unindexed fields, and make use
of them in the 'lcn index' command.

* include/lcn_field.h
  (lcn_field_keyword,
   lcn_field_unindexed): new declarations.

* src/cmdline/main.c
  (index_entry): index directories, add keyword fields to both directories
   and files to indicate their type, use unindexed fields to store paths.

* src/document/field.cxx
  (field_keyword_internal,
   lcn_field_keyword,
   field_unindexed_internal,
   lcn_field_uninexed): new functions.

Modified:
    incubator/lucene4c/trunk/include/lcn_field.h
    incubator/lucene4c/trunk/src/cmdline/main.c
    incubator/lucene4c/trunk/src/document/field.cxx

Modified: incubator/lucene4c/trunk/include/lcn_field.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/include/lcn_field.h?rev=201822&r1=201821&r2=201822&view=diff
==============================================================================
--- incubator/lucene4c/trunk/include/lcn_field.h (original)
+++ incubator/lucene4c/trunk/include/lcn_field.h Sat Jun 25 20:35:13 2005
@@ -38,6 +38,20 @@
                 const char *value,
                 apr_pool_t *pool);
 
+/** Create a keyword field. */
+lcn_error_t *
+lcn_field_keyword (lcn_field_t **f,
+                   const char *name,
+                   const char *value,
+                   apr_pool_t *pool);
+
+/** Create an unindexed field. */
+lcn_error_t *
+lcn_field_unindexed (lcn_field_t **f,
+                     const char *name,
+                     const char *value,
+                     apr_pool_t *pool);
+
 /** Return the name of field @a f in @a name, allocated in @a pool. */
 lcn_error_t *
 lcn_field_name (char **name, const lcn_field_t *f, apr_pool_t *pool);

Modified: incubator/lucene4c/trunk/src/cmdline/main.c
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/cmdline/main.c?rev=201822&r1=201821&r2=201822&view=diff
==============================================================================
--- incubator/lucene4c/trunk/src/cmdline/main.c (original)
+++ incubator/lucene4c/trunk/src/cmdline/main.c Sat Jun 25 20:35:13 2005
@@ -122,6 +122,8 @@
              int *nindexed,
              apr_pool_t *pool)
 {
+  lcn_document_t *doc;
+  lcn_field_t *field;
   apr_finfo_t finfo;
   apr_status_t rv;
 
@@ -129,11 +131,23 @@
   if (rv)
     return lcn_error_create (LCN_ERR_IO_EXCEPTION, "couldn't stat file");
 
+  LCN_ERR (lcn_document_create (&doc, pool));
+
+  printf ("indexing '%s'\n", entry);
+
+  LCN_ERR (lcn_field_unindexed (&field, "path", entry, pool));
+
+  LCN_ERR (lcn_document_add_field (doc, field));
+
   if (finfo.filetype == APR_DIR)
     {
       apr_pool_t *subpool;
       apr_dir_t *dir;
 
+      LCN_ERR (lcn_field_keyword (&field, "type", "directory", pool));
+
+      LCN_ERR (lcn_document_add_field (doc, field));
+
       rv = apr_dir_open (&dir, entry, pool);
       if (rv)
         return lcn_error_create (LCN_ERR_IO_EXCEPTION, "couldn't open dir");
@@ -165,27 +179,19 @@
     }
   else
     {
-      lcn_document_t *doc;
-      lcn_field_t *field;
-
-      LCN_ERR (lcn_document_create (&doc, pool));
-
-      printf ("indexing '%s'\n", entry);
-
-      /* XXX should be a keyword or something, so it isn't tokenized */
-      LCN_ERR (lcn_field_text (&field, "path", entry, pool));
+      LCN_ERR (lcn_field_keyword (&field, "type", "file", pool));
 
       LCN_ERR (lcn_document_add_field (doc, field));
 
       /* XXX should obviously index contents... */
+    }
 
-      LCN_ERR (lcn_index_writer_add_document (writer, doc, pool));
+  LCN_ERR (lcn_index_writer_add_document (writer, doc, pool));
 
-      if (++*nindexed % 10 == 0)
-        {
-          printf ("optimizing index\n");
-          LCN_ERR (lcn_index_writer_optimize (writer));
-        }
+  if (++*nindexed % 10 == 0)
+    {
+      printf ("optimizing index\n");
+      LCN_ERR (lcn_index_writer_optimize (writer));
     }
 
   return LCN_NO_ERROR;

Modified: incubator/lucene4c/trunk/src/document/field.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/document/field.cxx?rev=201822&r1=201821&r2=201822&view=diff
==============================================================================
--- incubator/lucene4c/trunk/src/document/field.cxx (original)
+++ incubator/lucene4c/trunk/src/document/field.cxx Sat Jun 25 20:35:13 2005
@@ -65,6 +65,66 @@
   return lcn__swallow_exception (field_text_internal, &ftb);
 }
 
+static void
+field_keyword_internal (void *b)
+{
+  field_text_baton *ftb = static_cast<field_text_baton *>(b);
+
+  *ftb->f = static_cast<lcn_field_t *>(apr_palloc (ftb->pool,
+                                                   sizeof (lcn_field_t)));
+
+  jstring name = JvNewStringUTF (ftb->name);
+  jstring value = JvNewStringUTF (ftb->value);
+
+  (*ftb->f)->impl = Field::Keyword (name, value);
+}
+
+lcn_error_t *
+lcn_field_keyword (lcn_field_t **f,
+                   const char *name,
+                   const char *value,
+                   apr_pool_t *pool)
+{
+  field_text_baton ftb;
+
+  ftb.f = f;
+  ftb.name = name;
+  ftb.value = value;
+  ftb.pool = pool;
+
+  return lcn__swallow_exception (field_keyword_internal, &ftb);
+}
+
+static void
+field_unindexed_internal (void *b)
+{
+  field_text_baton *ftb = static_cast<field_text_baton *>(b);
+
+  *ftb->f = static_cast<lcn_field_t *>(apr_palloc (ftb->pool,
+                                                   sizeof (lcn_field_t)));
+
+  jstring name = JvNewStringUTF (ftb->name);
+  jstring value = JvNewStringUTF (ftb->value);
+
+  (*ftb->f)->impl = Field::UnIndexed (name, value);
+}
+
+lcn_error_t *
+lcn_field_unindexed (lcn_field_t **f,
+                     const char *name,
+                     const char *value,
+                     apr_pool_t *pool)
+{
+  field_text_baton ftb;
+
+  ftb.f = f;
+  ftb.name = name;
+  ftb.value = value;
+  ftb.pool = pool;
+
+  return lcn__swallow_exception (field_unindexed_internal, &ftb);
+}
+
 struct field_name_baton {
   char **name;
   const lcn_field_t *f;
@@ -132,4 +192,5 @@
 
   return lcn__swallow_exception (field_content_internal, &fcb);
 }
+
 } // extern "C"



Mime
View raw message