lucene-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r178875 - in /incubator/lucene4c/branches/gcj-backend: Makefile include/lcn_types.h src/cmdline/main.c
Date Sat, 28 May 2005 18:31:01 GMT
Author: rooneg
Date: Sat May 28 11:31:00 2005
New Revision: 178875

URL: http://svn.apache.org/viewcvs?rev=178875&view=rev
Log:
Make the command line tool work again, sort of anyway.

* src/cmdline/main.c
  (lcn_segments_cmd, lcn_termdocs_cmd): removed.
  (dispatch_table): get rid of segments and termdocs entries.
  (print_doc_field): update arguments, stub out impl until we have an actual
   way to get at the fields inside a document.
  (lcn_search_cmd): update to use new APIs.
  (main): call lcn_init and lcn_thread_attach before using Lucene4c functions.

* include/lcn_types.h: resurrected, with useless parts removed.

* Makefile: build src/cmdline/lcn

Added:
    incubator/lucene4c/branches/gcj-backend/include/lcn_types.h
      - copied, changed from r171258, incubator/lucene4c/branches/gcj-backend/include/lcn_types.h
Modified:
    incubator/lucene4c/branches/gcj-backend/Makefile
    incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c

Modified: incubator/lucene4c/branches/gcj-backend/Makefile
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/Makefile?rev=178875&r1=178874&r2=178875&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/Makefile (original)
+++ incubator/lucene4c/branches/gcj-backend/Makefile Sat May 28 11:31:00 2005
@@ -25,6 +25,8 @@
      src/search/index_searcher.o \
      src/index/writer.o
 
+CMDLINE_OBJS= src/cmdline/main.o
+
 %.o: %.cxx
 	$(CXX) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
 
@@ -37,7 +39,7 @@
 %.class: %.java
 	javac -classpath lib/lucene-1.4.3.jar -d src $<
 
-all: lib/liblucene4c.so test/test include/org/apache/lucene4c/QueryParserHack.h include/org/apache/lucene4c/IndexSearcherHack.h
+all: lib/liblucene4c.so src/cmdline/lcn test/test include/org/apache/lucene4c/QueryParserHack.h
include/org/apache/lucene4c/IndexSearcherHack.h
 
 include/org/apache/lucene4c/QueryParserHack.h: src/org/apache/lucene4c/QueryParserHack.class
 	$(JCCH) --classpath lib/lucene-1.4.3.jar:src org.apache.lucene4c.QueryParserHack -d include
@@ -50,6 +52,9 @@
 
 test/test: lib/liblucene4c.so test/main.o
 	$(CC) $(CFLAGS) test/main.o -o $@ -Llib -Wl,-rpath=lib -llucene4c -L$(APR_ROOT)/.libs -Wl,-rpath=$(APR_ROOT)/.libs
-lapr-1
+
+src/cmdline/lcn: lib/liblucene4c.so $(CMDLINE_OBJS)
+	$(CC) $(CFLAGS) $(CMDLINE_OBJS) -o $@ -Llib -Wl,-rpath=lib -llucene4c -L$(APR_ROOT)/.libs
-Wl,-rpath=$(APR_ROOT)/.libs -lapr-1
 
 clean:
 	rm -f $(OBJS)

Copied: incubator/lucene4c/branches/gcj-backend/include/lcn_types.h (from r171258, incubator/lucene4c/branches/gcj-backend/include/lcn_types.h)
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_types.h?p2=incubator/lucene4c/branches/gcj-backend/include/lcn_types.h&p1=incubator/lucene4c/branches/gcj-backend/include/lcn_types.h&r1=171258&r2=178875&rev=178875&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_types.h (original)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_types.h Sat May 28 11:31:00 2005
@@ -23,7 +23,6 @@
 #define _LCN_TYPES_H
 
 #include <apr.h>
-#include <apr_pools.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,44 +41,6 @@
 #define TRUE 1
 #endif
 
-/** Our exception object. */
-typedef struct lcn_error_t {
-  apr_status_t apr_err;      /**< The underlying APR error */
-
-  const char *message;       /**< Human readable error message */
-
-  struct lcn_error_t *child; /**< The next error in the chain, or @c NULL */
-
-  apr_pool_t *pool;          /**< The pool this error was allocated in */
-
-} lcn_error_t;
-
-/** The best kind of error. */
-#define LCN_NO_ERROR 0
-
-/** Create a new error with underlying error code @a apr_err, wrapping around
- * @a child, with error message @a message.
- */
-lcn_error_t *
-lcn_error_create (apr_status_t apr_err,
-                  lcn_error_t *child,
-                  const char *message);
-
-/** A @c printf style version of @c lcn_error_create. */
-lcn_error_t *
-lcn_error_createf (apr_status_t apr_err,
-                   lcn_error_t *child,
-                   const char *fmt,
-                   ...)
-#ifdef DOXYGEN_SHOULD_SKIP_THIS
-                   ;
-#else
-                   __attribute__ ((format (printf, 3, 4)));
-#endif
-
-/** Destroy @a error. */
-void lcn_error_clear (lcn_error_t *error);
-
 /** A handy wrapper for functions that return an @c lcn_error_t, just returns
  * the error to our caller if it's not @c LCN_NO_ERROR.
  */
@@ -90,47 +51,11 @@
       return lcn_err__temp;              \
     } while (0)
 
-/** A java style 16 bit char. */
-typedef apr_uint16_t lcn_char_t;
-
-/** Count the number of characters in a string of lcn_char_t's */
-apr_size_t lcn_strlen (const lcn_char_t *str);
-
-/** Get the size of a string of lcn_char_t's in bytes */
-#define LCN_STRING_SIZE(str) ((lcn_strlen (str) + 1) * sizeof (lcn_char_t))
-
-/** Lexographically compare @a first and @a second. */
-int lcn_strcmp (const lcn_char_t *first, const lcn_char_t *second);
-
-/** Return a copy of @a str, allocated in @a pool. */
-lcn_char_t *
-lcn_strcpy (const lcn_char_t *str, apr_pool_t *pool);
-
-/** Convert @a in into a cstring @a out, allocated in @a pool.
- *
- * This will result in an error if @a in cannot be represented in ASCII
- * characters.
- */
-lcn_error_t *
-lcn_str_to_cstring (char **out, const lcn_char_t *in, apr_pool_t *pool);
-
-/** Create a string of @c lcn_char_ts that corresponds to the contents of 
- * @a in, allocated in @a pool.
- */
-lcn_char_t *
-lcn_str_from_cstring (const char *in, apr_pool_t *pool);
-
 /** Index into an apr_array_header_t */
 #define APR_ARRAY_IDX(ary,i,type) (((type *)(ary)->elts)[i])
 
 /** Easier array-pushing syntax */
 #define APR_ARRAY_PUSH(ary,type) (*((type *)apr_array_push (ary)))
-
-/** A convenience wrapper for @c apr_pool_create. */
-apr_pool_t *lcn_pool_create (apr_pool_t *parent);
-
-/** For symmetry with @c lcn_pool_create. */
-#define lcn_pool_destroy apr_pool_destroy
 
 #ifdef __cplusplus
 }

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=178875&r1=178874&r2=178875&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c (original)
+++ incubator/lucene4c/branches/gcj-backend/src/cmdline/main.c Sat May 28 11:31:00 2005
@@ -15,19 +15,22 @@
  */
 
 #include <stdlib.h>
+#include <stdio.h>
 
 #include <apr.h>
 
-#include "lcn_index.h"
+#include "lcn_init.h"
 #include "lcn_types.h"
-#include "lcn_segments.h"
+#include "lcn_pools.h"
 #include "lcn_query_parser.h"
+#include "lcn_searcher.h"
+#include "lcn_document.h"
 
 typedef lcn_error_t *(lcn_subcommand_t) (int argc,
                                          char *argv[],
                                          apr_pool_t *pool);
 
-lcn_subcommand_t lcn_segments_cmd, lcn_termdocs_cmd, lcn_search_cmd;
+lcn_subcommand_t lcn_search_cmd;
 
 typedef struct {
   const char *name;
@@ -35,134 +38,21 @@
 } subcommand_desc_t;
 
 subcommand_desc_t dispatch_table[] = {
-  { "segments", lcn_segments_cmd },
-  { "termdocs", lcn_termdocs_cmd },
   { "search", lcn_search_cmd },
   { NULL }
 };
 
-lcn_error_t *
-lcn_segments_cmd (int argc, char *argv[], apr_pool_t *pool)
-{
-  if (argc != 1)
-    {
-      printf ("usage: lcn segments <index>\n");
-      return lcn_error_create (APR_EGENERAL, NULL, "missing argument");
-    }
-  else
-    {
-      apr_array_header_t *names;
-      lcn_segments_t *segs;
-      lcn_directory_t *d;
-      int i;
-
-      LCN_ERR (lcn_fs_directory_open (&d, argv[0], pool));
-
-      LCN_ERR (lcn_segments_read (&segs, d, pool));
-
-      names = lcn_segments_names (segs, pool);
-
-      for (i = 0; i < names->nelts; ++i)
-        {
-          lcn_char_t *name = APR_ARRAY_IDX (names, i, lcn_char_t *);
-          char *pname;
-
-          LCN_ERR (lcn_str_to_cstring (&pname, name, pool));
-
-          printf ("%s\n", pname);
-        }
-
-      return LCN_NO_ERROR;
-    }
-}
-
 static lcn_error_t *
-print_doc_field (lcn_index_t *idx,
-                 apr_uint32_t doc_num,
-                 lcn_char_t *pfield,
+print_doc_field (lcn_document_t *doc,
+                 const char *fieldname,
                  apr_pool_t *pool)
 {
-  const lcn_field_t *field;
-  lcn_document_t *doc;
-  char *cstr;
-
-  LCN_ERR (lcn_index_get_document (&doc, idx, doc_num, pool));
-
-  field = lcn_document_field_by_name (doc, pfield);
-  if (field)
-    {
-      const lcn_char_t *cont;
-
-      cont = lcn_field_content (field);
-
-      LCN_ERR (lcn_str_to_cstring (&cstr, cont, pool));
-
-      printf ("%s\n", cstr);
-    }
-  else
-    {
-      LCN_ERR (lcn_str_to_cstring (&cstr, pfield, pool));
-
-      return lcn_error_createf (APR_EINVAL,
-                                NULL,
-                                "field '%s' does not exist",
-                                cstr);
-    }
+  printf ("if i had finished this code, i'd print a field now...\n");
 
   return LCN_NO_ERROR;
 }
 
 lcn_error_t *
-lcn_termdocs_cmd (int argc, char *argv[], apr_pool_t *pool)
-{
-  if (argc != 4)
-    {
-      printf ("usage: lcn termdocs <index> <term> <field> <pfield>\n");
-      return LCN_NO_ERROR;
-    }
-  else
-    {
-      lcn_doc_iter_t *itr;
-      apr_pool_t *subpool;
-      lcn_boolean_t next;
-      lcn_char_t *pfield;
-      lcn_error_t *err;
-      lcn_index_t *idx;
-      lcn_term_t t;
-
-      LCN_ERR (lcn_index_open (&idx, argv[0], pool));
-
-      t.contents = lcn_str_from_cstring (argv[1], pool);
-
-      t.field = lcn_str_from_cstring (argv[2], pool);
-
-      pfield = lcn_str_from_cstring (argv[3], pool);
-
-      LCN_ERR (lcn_index_term_docs (&itr, idx, &t, pool));
-
-      subpool = lcn_pool_create (pool);
-
-      LCN_ERR (print_doc_field (idx, lcn_doc_iter_doc (itr), pfield, subpool));
-
-      while ((err = lcn_doc_iter_next (&next, itr)) == LCN_NO_ERROR && next)
-        {
-          apr_pool_clear (subpool);
-
-          LCN_ERR (print_doc_field (idx,
-                                    lcn_doc_iter_doc (itr),
-                                    pfield,
-                                    subpool));
-        }
-
-      LCN_ERR (lcn_doc_iter_close (itr));
-
-      lcn_pool_destroy (subpool);
-
-      return LCN_NO_ERROR;
-    }
-}
-
-lcn_error_t *
 lcn_search_cmd (int argc, char *argv[], apr_pool_t *pool)
 {
   if (argc != 3)
@@ -172,45 +62,40 @@
     }
   else
     {
-      lcn_char_t *pfield = lcn_str_from_cstring (argv[2], pool);
-      apr_pool_t *subpool = lcn_pool_create (pool);
-      lcn_query_parser_t *parser;
-      lcn_scorer_t *scorer;
-      lcn_weight_t *weight;
-      lcn_boolean_t next;
+      apr_array_header_t *results;
+      lcn_searcher_t *searcher;
+      lcn_analyzer_t *analyzer;
+      apr_pool_t *subpool;
       lcn_query_t *query;
-      lcn_index_t *idx;
-      lcn_error_t *err;
-
-      LCN_ERR (lcn_index_open (&idx, argv[0], pool));
-
-      LCN_ERR (lcn_query_parser_create (&parser,
-                                        lcn_str_from_cstring ("contents",
-                                                              pool),
-                                        LCN_SHOULD,
-                                        pool));
+      int idx;
 
-      LCN_ERR (lcn_query_parser_parse (&query,
-                                       parser,
-                                       lcn_str_from_cstring (argv[1], pool),
-                                       pool));
+      LCN_ERR (lcn_analyzer_standard_create (&analyzer, pool));
 
-      LCN_ERR (lcn_query_weight (&weight, query, idx, pool));
+      LCN_ERR (lcn_query_parse (&query,
+                                argv[1],
+                                "contents",
+                                analyzer,
+                                pool));
+
+      LCN_ERR (lcn_index_searcher_open (&searcher, argv[0], pool));
+
+      LCN_ERR (lcn_searcher_search (&results,
+                                    searcher,
+                                    query,
+                                    NULL,
+                                    NULL,
+                                    pool));
 
-      LCN_ERR (lcn_weight_scorer (&scorer, weight, pool));
-
-      LCN_ERR (print_doc_field (idx,
-                                lcn_scorer_doc (scorer),
-                                pfield,
-                                subpool));
+      subpool = lcn_pool_create (pool);
 
-      while ((err = lcn_scorer_next (&next, scorer)) == LCN_NO_ERROR && next)
+      for (idx = 0; idx < results->nelts; ++idx)
         {
           apr_pool_clear (subpool);
 
-          LCN_ERR (print_doc_field (idx,
-                                    lcn_scorer_doc (scorer),
-                                    pfield,
+          LCN_ERR (print_doc_field (APR_ARRAY_IDX (results,
+                                                   idx,
+                                                   lcn_document_t *),
+                                    argv[2],
                                     subpool));
         }
 
@@ -229,6 +114,10 @@
   apr_initialize ();
 
   atexit (apr_terminate);
+
+  lcn_init ();
+
+  lcn_thread_attach ();
 
   pool = lcn_pool_create (NULL);
 



Mime
View raw message