lucene-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r171264 - in /incubator/lucene4c/branches/gcj-backend: ./ include/ lib/ src/analysis/ src/document/ src/index/ src/query_parser/ src/search/ src/store/ src/util/ test/
Date Sat, 21 May 2005 23:20:21 GMT
Author: rooneg
Date: Sat May 21 16:20:19 2005
New Revision: 171264

URL: http://svn.apache.org/viewcvs?rev=171264&view=rev
Log:
Checkpoint my current work in progress on making Lucene4c into a thin C
layer on top of a GCJ compiled version of Java Lucene.  This is somewhat
incomplete at this point, but so far you can create documents and fields,
index them, and the interface for searching has been sketched out.

Still on the todo list are getting the build system back to using the GNU
autotools, making the unit tests work, and making the cli work with the
new interface.

* test/main.c: new temporary test program.

* include/lcn_scorer.h: removed.

* include/lcn_segment.h: removed.

* include/lcn_init.h: new header, holds functions for initializing the
  lucene4c library.

* include/lcn_index_writer.h: new header, holds functions for working
  with an index writer object.

* include/lcn_directory.h: removed.

* include/lcn_istream.h: removed.

* include/lcn_types.h: removed.

* include/lcn_query.h
  (lcn_term_query_create): removed.
  (lcn_query_to_string): new declaration.
  (lcn_boolean_query_create): removed.
  (lcn_boolean_clause_occur_t): removed.
  (lcn_boolean_query_add): removed.
  (lcn_weight_query): removed.
  (lcn_weight_value): removed.
  (lcn_weight_sum_of_squared_weights): removed.
  (lcn_weight_normalize): removed.
  (lcn_query_weight): removed.
  (lcn_weight_scorer): removed.

* include/lcn_terminfos.h: removed.

* include/lcn_index.h: removed.

* include/lcn_term.h: removed.

* include/lcn_frequencies.h: removed.

* include/lcn_api.h: removed.

* include/lcn_fielddata.h: removed.

* include/lcn_document.h
  (lcn_document_create): update to return an error.
  (lcn_document_numfields): removed.
  (lcn_document_add_field): update to return an error.
  (lcn_document_field_by_num): removed.
  (lcn_document_field_by_name): removed.

* include/lcn_query_parser.h: removed.

* include/lcn_fieldinfos.h: removed.

* include/lcn_field.h
  (lcn_field_text): new function.
  (lcn_field_name): return an error.
  (lcn_field_content): ditto.
  (lcn_field_stored_t): removed.
  (lcn_field_indexed_t): removed.
  (lcn_field_termvector_t): removed.
  (lcn_field_create): removed.

* include/lcn_index_searcher.h: new, holds interface for an index searcher
  object.

* include/lcn_segments.h: removed.

* include/lcn_analyzer.h: new, holds interface for analyzer objects.

* include/lcn_error.h: new, holds interface for C level exception objects.

* include/lcn_pools.h: new, holds wrapper functions for dealing with APR
  memory pools.

* src/analysis/standard.cxx: new, holds code for the standard analyzer.

* src/analysis/analyzer.hxx: new, holds C++ structs for wrapping Java level
  analyzer objects.

* src/search/query.c: deleted.

* src/search/scorer.c: deleted.

* src/index/fieldinfos.c: deleted.

* src/index/segment.c: deleted.

* src/index/segments.c: deleted.

* src/index/terminfos.c: deleted.

* src/index/term.c: deleted.

* src/index/index.c: deleted.

* src/index/frequencies.c: deleted.

* src/index/writer.cxx: new, holds code for wrapping index writer objects.

* src/index/fielddata.c: deleted.

* src/store/istream.c: deleted.

* src/store/directory.c: deleted.

* src/util/exception.cxx: new, holds code for turning Java exceptions into
  C level objects.

* src/util/exception.h: new, holds internal interfaces for accessing code
  from exception.cxx.

* src/util/init.cxx: new, holds code for initializing Lucene4c.

* src/util/string.c: deleted.

* src/util/error.c
  (make_error_internal): removed.
  (lcn_error_create): alter interface a bit.
  (lcn_error_createf): removed for now.

* src/document/document.c: removed.

* src/document/document.cxx: new, holds wrappers for document objects.

* src/document/field.c: removed.

* src/document/field.cxx: new, holds wrappers for field objects.

* src/document/document.hxx: new, holds C++ level structures for wrapping
  document objects.

* src/document/field.hxx: new, holds C++ level structures for wrapping 
  field objects.

* lib/lucene-1.4.3.jar: compiled Java library we'll be wrapping.

* Makefile: a temporary makefile to build all this stuff.

Added:
    incubator/lucene4c/branches/gcj-backend/Makefile
    incubator/lucene4c/branches/gcj-backend/include/lcn_analyzer.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_error.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_index_searcher.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_index_writer.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_init.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_pools.h
    incubator/lucene4c/branches/gcj-backend/lib/   (with props)
    incubator/lucene4c/branches/gcj-backend/lib/lucene-1.4.3.jar   (with props)
    incubator/lucene4c/branches/gcj-backend/src/analysis/
    incubator/lucene4c/branches/gcj-backend/src/analysis/analyzer.hxx
    incubator/lucene4c/branches/gcj-backend/src/analysis/standard.cxx
    incubator/lucene4c/branches/gcj-backend/src/document/document.cxx
    incubator/lucene4c/branches/gcj-backend/src/document/document.hxx
    incubator/lucene4c/branches/gcj-backend/src/document/field.cxx
    incubator/lucene4c/branches/gcj-backend/src/document/field.hxx
    incubator/lucene4c/branches/gcj-backend/src/index/writer.cxx
    incubator/lucene4c/branches/gcj-backend/src/util/exception.cxx
    incubator/lucene4c/branches/gcj-backend/src/util/exception.h
    incubator/lucene4c/branches/gcj-backend/src/util/init.cxx
    incubator/lucene4c/branches/gcj-backend/test/main.c
Removed:
    incubator/lucene4c/branches/gcj-backend/include/lcn_api.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_directory.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_fielddata.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_fieldinfos.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_frequencies.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_index.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_istream.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_query_parser.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_scorer.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_segment.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_segments.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_term.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_terminfos.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_types.h
    incubator/lucene4c/branches/gcj-backend/src/document/document.c
    incubator/lucene4c/branches/gcj-backend/src/document/field.c
    incubator/lucene4c/branches/gcj-backend/src/index/fielddata.c
    incubator/lucene4c/branches/gcj-backend/src/index/fieldinfos.c
    incubator/lucene4c/branches/gcj-backend/src/index/frequencies.c
    incubator/lucene4c/branches/gcj-backend/src/index/index.c
    incubator/lucene4c/branches/gcj-backend/src/index/segment.c
    incubator/lucene4c/branches/gcj-backend/src/index/segments.c
    incubator/lucene4c/branches/gcj-backend/src/index/term.c
    incubator/lucene4c/branches/gcj-backend/src/index/terminfos.c
    incubator/lucene4c/branches/gcj-backend/src/query_parser/parser.c
    incubator/lucene4c/branches/gcj-backend/src/search/query.c
    incubator/lucene4c/branches/gcj-backend/src/search/scorer.c
    incubator/lucene4c/branches/gcj-backend/src/store/
    incubator/lucene4c/branches/gcj-backend/src/util/string.c
Modified:
    incubator/lucene4c/branches/gcj-backend/include/   (props changed)
    incubator/lucene4c/branches/gcj-backend/include/lcn_document.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_field.h
    incubator/lucene4c/branches/gcj-backend/include/lcn_query.h
    incubator/lucene4c/branches/gcj-backend/src/util/error.c
    incubator/lucene4c/branches/gcj-backend/test/   (props changed)

Added: incubator/lucene4c/branches/gcj-backend/Makefile
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/Makefile?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/Makefile (added)
+++ incubator/lucene4c/branches/gcj-backend/Makefile Sat May 21 16:20:19 2005
@@ -0,0 +1,60 @@
+APR_ROOT=../apr-trunk
+GCC_ROOT=/home/rooneg/work/gcj
+
+CPPFLAGS=`$(APR_ROOT)/apr-1-config --cppflags`
+CFLAGS=`$(APR_ROOT)/apr-1-config --cflags`
+INCLUDES=-Iinclude -I$(APR_ROOT)/include
+
+CC=$(GCC_ROOT)/bin/gcc -Wall
+CXX=$(GCC_ROOT)/bin/g++ -Wall
+JCC=$(GCC_ROOT)/bin/gcj -Wall
+JCCH=$(GCC_ROOT)/bin/gcjh
+JAR=$(GCC_ROOT)/bin/fastjar
+
+OBJS=src/util/exception.o \
+     src/util/error.o \
+     src/util/init.o \
+     src/util/pools.o \
+     src/document/field.o \
+     src/document/document.o \
+     src/analysis/standard.o \
+     src/index/writer.o
+
+%.o: %.cxx
+	$(CXX) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
+
+%.o: %.c
+	$(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
+
+all: lib/liblucene4c.so test/test
+
+test/test: lib/liblucene4c.so test/main.o
+	$(CXX) $(CFLAGS) test/main.o -o $@ -Llib -Wl,-rpath=lib -llucene4c -L$(APR_ROOT)/.libs -Wl,-rpath=$(APR_ROOT)/.libs -lapr-1
+
+clean:
+	rm -f $(OBJS)
+	rm -f lib/lucene.o
+	rm -f lib/liblucene4c.so
+	rm -f tests/test
+
+lib/lucene.o: lib/lucene-1.4.3.jar
+	$(JCC) -c -o $@ lib/lucene-1.4.3.jar
+
+lib/liblucene4c.so: $(OBJS) lib/lucene.o
+	$(CC) -shared -o $@ $(OBJS) lib/lucene.o -lgcj -Wl,-rpath=$(APR_ROOT)/.libs -L$(APR_ROOT)/.libs -lapr-1
+
+# XXX gcjh barfs on some lucene classes, needs to be fixed.
+
+headers:
+	$(JAR) xvf lib/lucene-1.4.3.jar
+	rm -rf META-INF
+	mkdir .tmp && mv org .tmp/org
+	find .tmp -type d | \
+        sed 's|\.tmp/|include/|' | \
+        xargs mkdir -p
+	find .tmp -name \*.class | \
+        sed 's|\.tmp/||' | \
+        sed 's|\.class||' | \
+        sed 's|/|.|g' | \
+        xargs $(JCCH) -d include --classpath=lib/lucene-1.4.3.jar
+	rm -rf .tmp

Propchange: incubator/lucene4c/branches/gcj-backend/include/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat May 21 16:20:19 2005
@@ -0,0 +1 @@
+org

Added: incubator/lucene4c/branches/gcj-backend/include/lcn_analyzer.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_analyzer.h?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_analyzer.h (added)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_analyzer.h Sat May 21 16:20:19 2005
@@ -0,0 +1,38 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#ifndef _LCN_ANALYZER_H
+#define _LCN_ANALYZER_H
+
+#include "lcn_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** An analyzer object. */
+typedef struct lcn_analyzer_t lcn_analyzer_t;
+
+/** Create a "standard" @a analyzer, allocated in @a pool. */
+lcn_error_t *
+lcn_analyzer_standard_create (lcn_analyzer_t **analyzer,
+                              apr_pool_t *pool);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_ANALYZER_H */

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=171264&r1=171263&r2=171264&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_document.h (original)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_document.h Sat May 21 16:20:19 2005
@@ -22,7 +22,6 @@
 #ifndef _LCN_DOCUMENT_H
 #define _LCN_DOCUMENT_H
 
-#include "lcn_types.h"
 #include "lcn_field.h"
 
 #ifdef __cplusplus
@@ -32,25 +31,13 @@
 /** Opaque structure representing a document in the index. */
 typedef struct lcn_document_t lcn_document_t;
 
-/** Create an empty document, allocated from @a pool. */
-lcn_document_t *
-lcn_document_create (apr_pool_t *pool);
-
-/** Return the number of fields in document @a doc. */
-apr_uint32_t lcn_document_numfields (lcn_document_t *doc);
+/** Return an empty document in @a document, allocated from @a pool. */
+lcn_error_t *
+lcn_document_create (lcn_document_t **document, apr_pool_t *pool);
 
 /** Add @a field to @a doc. */
-void lcn_document_add_field (lcn_document_t *doc, lcn_field_t *field);
-
-/** Return field number @a num from @a doc, or @c NULL if it does not exist. */
-const lcn_field_t *
-lcn_document_field_by_num (const lcn_document_t *doc,
-                           apr_uint32_t num);
-
-/** Return field @a name from @a doc, or @c NULL if it does not exist. */
-const lcn_field_t *
-lcn_document_field_by_name (const lcn_document_t *doc,
-                            const lcn_char_t *name);
+lcn_error_t *
+lcn_document_add_field (lcn_document_t *doc, lcn_field_t *field);
 
 #ifdef __cplusplus
 }

Added: 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=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_error.h (added)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_error.h Sat May 21 16:20:19 2005
@@ -0,0 +1,59 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#ifndef _LCN_ERROR_H
+#define _LCN_ERROR_H
+
+#include <apr_pools.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** Error codes for various types of exceptions. */
+typedef enum {
+  LCN_RUNTIME_EXCEPTION,
+  LCN_IO_EXCEPTION,
+  LCN_ILLEGAL_ARGUMENT_EXCEPTION
+} lcn_error_code_t;
+
+/** The best kind of @c lcn_error_t. */
+#define LCN_NO_ERROR NULL
+
+/** An error object. */
+typedef struct {
+  /** The error code that describes the cause of this error. */
+  lcn_error_code_t code;
+
+  /** A textual description of the error. */
+  const char *message;
+
+  /** The pool this error was allocated from. */
+  apr_pool_t *pool;
+} lcn_error_t;
+
+/** Create a new @c lcn_error_t with @a code and @a reason. */
+lcn_error_t *
+lcn_error_create (lcn_error_code_t code, const char *reason);
+
+/** Deallocate any memory used by @a err. */
+void lcn_error_clear (lcn_error_t *err);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_ERROR_H */

Modified: incubator/lucene4c/branches/gcj-backend/include/lcn_field.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_field.h?rev=171264&r1=171263&r2=171264&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_field.h (original)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_field.h Sat May 21 16:20:19 2005
@@ -22,7 +22,7 @@
 #ifndef _LCN_FIELD_H
 #define _LCN_FIELD_H
 
-#include "lcn_types.h"
+#include "lcn_error.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -31,61 +31,20 @@
 /** Opaque structure representing a field in a document. */
 typedef struct lcn_field_t lcn_field_t;
 
-/** Indicates if a field is stored in the index or not. */
-typedef enum {
-  LCN_STORED_NO,       /**< Field is not stored */
-  LCN_STORED_YES,      /**< Field is stored */
-  LCN_STORED_COMPRESS  /**< Field is stored in compressed form */
-} lcn_field_stored_t;
-
-/** Indicates if a field is indexed or not. */
-typedef enum {
-  LCN_INDEXED_NO,          /**< Field is not indexed */
-  LCN_INDEXED_TOKENIZED,   /**< Field is indexed in tokenized form */
-  LCN_INDEXED_UNTOKENIZED  /**< Field is indexed without being tokenized */
-} lcn_field_indexed_t;
-
-/** Indicates if a field is stored in the index's termvector. */
-typedef enum {
-  /** Field is not stored in the termvector */
-  LCN_TERMVECTOR_NO,
-
-  /** Field is stored in the termvector */
-  LCN_TERMVECTOR_YES,
-
-  /** Field is stored in the termvector along with its positions */
-  LCN_TERMVECTOR_WITH_POSITIONS,
-
-  /** Field is stored in the termvector along with its offsets */
-  LCN_TERMVECTOR_WITH_OFFSETS,
-
-  /** Field is stored in the termvector along with its positions and offsets */
-  LCN_TERMVECTOR_WITH_POSITIONS_OFFSETS
-} lcn_field_termvector_t;
-
-/** Create new field.
- *
- * The field will have the name @a name, the value @a value, and its status
- * with regard to storage, indexing, and termvector are determined by the
- * @a stored, @a indexed, and @a termvector arguments.
- *
- * All allocation is done with @a pool.
- */
-lcn_field_t *
-lcn_field_create (const lcn_char_t *name,
-                  const lcn_char_t *value,
-                  lcn_field_stored_t stored,
-                  lcn_field_indexed_t indexed,
-                  lcn_field_termvector_t termvector,
-                  apr_pool_t *pool);
-
-/** Return the name of field @a f. */
-const lcn_char_t *
-lcn_field_name (const lcn_field_t *f);
-
-/** Return the content of field @a f. */
-const lcn_char_t *
-lcn_field_content (const lcn_field_t *f);
+/** Create a text field. */
+lcn_error_t *
+lcn_field_text (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);
+
+/** Return the content of field @a f in @a content, allocated in @a pool. */
+lcn_error_t *
+lcn_field_content (char **content, const lcn_field_t *f, apr_pool_t *pool);
 
 #ifdef __cplusplus
 }

Added: incubator/lucene4c/branches/gcj-backend/include/lcn_index_searcher.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_index_searcher.h?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_index_searcher.h (added)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_index_searcher.h Sat May 21 16:20:19 2005
@@ -0,0 +1,49 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include "lcn_pools.h"
+#include "lcn_query.h"
+
+#include <apr_tables.h>
+
+#ifndef _LCN_INDEX_SEARCHER_H
+#define _LCN_INDEX_SEARCHER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct lcn_index_searcher_t lcn_index_searcher_t;
+
+lcn_error_t *
+lcn_index_searcher_open (lcn_index_searcher_t **searcher,
+                         const char *path,
+                         apr_pool_t *pool);
+
+lcn_error_t *
+lcn_index_searcher_search (apr_array_header_t **hits,
+                           lcn_index_searcher_t *searcher,
+                           lcn_query_t *query,
+                           apr_pool_t *pool);
+
+lcn_error_t *
+lcn_index_searcher_close (lcn_index_searcher_t *searcher);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_INDEX_SEARCHER_H */

Added: incubator/lucene4c/branches/gcj-backend/include/lcn_index_writer.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_index_writer.h?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_index_writer.h (added)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_index_writer.h Sat May 21 16:20:19 2005
@@ -0,0 +1,65 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#ifndef _LCN_INDEX_WRITER_H
+#define _LCN_INDEX_WRITER_H
+
+#include "lcn_document.h"
+#include "lcn_analyzer.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** An index writer object. */
+typedef struct lcn_index_writer_t lcn_index_writer_t;
+
+/** Open a new @a writer that will create an index at @a path, using
+ * @a analyzer, allocated in @a pool. */
+lcn_error_t *
+lcn_index_writer_create (lcn_index_writer_t **writer,
+                         const char *path,
+                         lcn_analyzer_t *analyzer,
+                         apr_pool_t *pool);
+
+/** Open a new @a writer that will write to an index that already exists at
+ * @a path, using @a analyzer, allocated in @a pool. */
+lcn_error_t *
+lcn_index_writer_open (lcn_index_writer_t **writer,
+                       const char *path,
+                       lcn_analyzer_t *analyzer,
+                       apr_pool_t *pool);
+
+/** Add @a document to the index referred to by @a writer, using @a pool for
+ * temporary allocations. */
+lcn_error_t *
+lcn_index_writer_add_document (lcn_index_writer_t *writer,
+                               lcn_document_t *document,
+                               apr_pool_t *pool);
+
+/** Close @a writer.
+ *
+ * Strictly speaking, this is not needed, as it will be closed when the pool
+ * @a writer was allocated in is cleared, but it can be useful when you need
+ * to close a writer before its pool is cleared. */
+lcn_error_t *
+lcn_index_writer_close (lcn_index_writer_t *writer);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_INDEX_WRITER_H */

Added: incubator/lucene4c/branches/gcj-backend/include/lcn_init.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_init.h?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_init.h (added)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_init.h Sat May 21 16:20:19 2005
@@ -0,0 +1,45 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#ifndef _LCN_INIT_H
+#define _LCN_INIT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** Initialize the Lucene4c library.
+ *
+ * This must be called before any other Lucene4c function. */
+void lcn_init (void);
+
+/** Initialize Lucene4c per-thread data structures.
+ *
+ * This must be called before any other Lucene4c functions (other than
+ * @c lcn_init) are called in a given thread. */
+void lcn_thread_attach (void);
+
+/** Clear Lucene4c per-thread data structures.
+ *
+ * This should be called before a thread that called @c lcn_thread_attach
+ * is destroyed, so that Lucene4c can clean up its per-thread data. */
+void lcn_thread_detach (void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_INIT_H */

Added: incubator/lucene4c/branches/gcj-backend/include/lcn_pools.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_pools.h?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_pools.h (added)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_pools.h Sat May 21 16:20:19 2005
@@ -0,0 +1,36 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#ifndef _LCN_POOLS_H
+#define _LCN_POOLS_H
+
+#include <apr_pools.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** 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
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_POOLS_H */

Modified: incubator/lucene4c/branches/gcj-backend/include/lcn_query.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/include/lcn_query.h?rev=171264&r1=171263&r2=171264&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/include/lcn_query.h (original)
+++ incubator/lucene4c/branches/gcj-backend/include/lcn_query.h Sat May 21 16:20:19 2005
@@ -22,10 +22,6 @@
 #ifndef _LCN_QUERY_H
 #define _LCN_QUERY_H
 
-#include "lcn_types.h"
-#include "lcn_scorer.h"
-#include "lcn_term.h"
-
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -33,69 +29,10 @@
 /** Abstract query object. */
 typedef struct lcn_query_t lcn_query_t;
 
-/** Create a @a query that matches @a term, allocated in @a pool. */
-lcn_error_t *
-lcn_term_query_create (lcn_query_t **query,
-                       lcn_term_t *term,
-                       apr_pool_t *pool);
-
-/** Create a @a query that matches a number of other queries, each of which
- * either MUST occur, SHOULD occur, or MUST NOT occur in the documents matched,
- * the query is allocated in @a pool.
- */
-lcn_error_t *
-lcn_boolean_query_create (lcn_query_t **query, apr_pool_t *pool);
-
-/** An indication of what requirement is placed on a particular part of a
- * boolean query.
- */
-typedef enum {
-  LCN_MUST,    /**< The query must match */
-  LCN_SHOULD,  /**< At least one of the queries with this occur must match */
-  LCN_MUST_NOT /**< The query must not match */
-} lcn_boolean_clause_occur_t;
-
-/** Add @a clause to @a query, with @a occur as the specification for whether
- * it is required or not.
- *
- * @note all clauses that are added to @a query must be allocated from a pool
- * that lives at least as long as the pool used to allocate @a query, or the
- * behavior is undefined.
- */
-lcn_error_t *
-lcn_boolean_query_add (lcn_query_t *query,
-                       lcn_query_t *clause,
-                       lcn_boolean_clause_occur_t occur);
-
-/** Return @a weight's underlying query. */
-lcn_query_t * lcn_weight_query (lcn_weight_t *weight);
-
-/** Return the value of @a weight. */
-float lcn_weight_value (lcn_weight_t *weight);
-
-/** Return the sum of the squared weight sof contained query clauses. */
-lcn_error_t *
-lcn_weight_sum_of_squared_weights (float *sum, lcn_weight_t *weight);
-
-/** Assign a query normalization factor @a norm to this @a weight. */
-lcn_error_t * lcn_weight_normalize (lcn_weight_t *weight, float norm);
-
-/* XXX leaving out lcn_weight_explain for now... */
-
-/** Create an @a weight from @a query, to be run over @a index and allocated
- * from @a pool.
- */
-lcn_error_t *
-lcn_query_weight (lcn_weight_t **weight,
-                  lcn_query_t *query,
-                  lcn_index_t *index,
-                  apr_pool_t *pool);
-
-/** Return a @a scorer for @a weight, allocated in @a pool. */
-lcn_error_t *
-lcn_weight_scorer (lcn_scorer_t **scorer,
-                   lcn_weight_t *weight,
-                   apr_pool_t *pool);
+lcn_error_t
+lcn_query_to_string(char **str,
+                    lcn_query_t *query,
+                    apr_pool_t *pool);
 
 #ifdef __cplusplus
 }

Propchange: incubator/lucene4c/branches/gcj-backend/lib/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat May 21 16:20:19 2005
@@ -0,0 +1 @@
+liblucene4c.so

Added: incubator/lucene4c/branches/gcj-backend/lib/lucene-1.4.3.jar
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/lib/lucene-1.4.3.jar?rev=171264&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/lucene4c/branches/gcj-backend/lib/lucene-1.4.3.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/lucene4c/branches/gcj-backend/src/analysis/analyzer.hxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/analysis/analyzer.hxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/analysis/analyzer.hxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/analysis/analyzer.hxx Sat May 21 16:20:19 2005
@@ -0,0 +1,30 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <org/apache/lucene/analysis/Analyzer.h>
+
+#ifndef _ANALYZER_HXX
+#define _ANALYZER_HXX
+
+extern "C" {
+
+struct lcn_analyzer_t {
+  ::org::apache::lucene::analysis::Analyzer *impl;
+};
+
+} // extern "C"
+
+#endif // _ANALYZER_HXX

Added: incubator/lucene4c/branches/gcj-backend/src/analysis/standard.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/analysis/standard.cxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/analysis/standard.cxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/analysis/standard.cxx Sat May 21 16:20:19 2005
@@ -0,0 +1,62 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <gcj/cni.h>
+
+#include <org/apache/lucene/analysis/Analyzer.h>
+#include <org/apache/lucene/analysis/standard/StandardAnalyzer.h>
+
+#include "lcn_analyzer.h"
+
+#include "analyzer.hxx"
+
+#include "../util/exception.h"
+
+using namespace org::apache::lucene::analysis::standard;
+
+extern "C" {
+
+struct analyzer_standard_create_baton {
+  lcn_analyzer_t **analyzer;
+  apr_pool_t *pool;
+};
+
+static void
+analyzer_standard_create_internal (void *b)
+{
+  analyzer_standard_create_baton *ascb
+    = static_cast<analyzer_standard_create_baton *>(b);
+
+  *ascb->analyzer
+    = static_cast<lcn_analyzer_t *>(apr_palloc (ascb->pool,
+                                                sizeof (lcn_analyzer_t)));
+
+  (*ascb->analyzer)->impl = new StandardAnalyzer;
+}
+
+lcn_error_t *
+lcn_analyzer_standard_create (lcn_analyzer_t **analyzer,
+                              apr_pool_t *pool)
+{
+  analyzer_standard_create_baton ascb;
+
+  ascb.analyzer = analyzer;
+  ascb.pool = pool;
+
+  return lcn__swallow_exception (analyzer_standard_create_internal, &ascb);
+}
+
+} // extern "C"

Added: 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=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/document/document.cxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/document/document.cxx Sat May 21 16:20:19 2005
@@ -0,0 +1,83 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <gcj/cni.h>
+
+#include <org/apache/lucene/document/Document.h>
+
+#include "lcn_document.h"
+
+#include "document.hxx"
+#include "field.hxx"
+
+#include "../util/exception.h"
+
+using namespace org::apache::lucene::document;
+
+extern "C" {
+
+struct document_create_baton {
+  lcn_document_t **d;
+  apr_pool_t *pool;
+};
+
+static void
+document_create_internal (void *b)
+{
+  document_create_baton *dcb = static_cast<document_create_baton *>(b);
+
+  *dcb->d = static_cast<lcn_document_t *>(apr_pcalloc (dcb->pool,
+                                                       sizeof (*dcb->d)));
+  (*dcb->d)->impl = new Document;
+}
+
+lcn_error_t *
+lcn_document_create (lcn_document_t **d,
+                     apr_pool_t *pool)
+{
+  document_create_baton dcb;
+
+  dcb.d = d;
+  dcb.pool = pool;
+
+  return lcn__swallow_exception (document_create_internal, &dcb);
+}
+
+struct document_add_field_baton {
+  lcn_document_t *doc;
+  lcn_field_t *field;
+};
+
+static void
+document_add_field_internal (void *b)
+{
+  document_add_field_baton *dafb = static_cast<document_add_field_baton *>(b);
+
+  dafb->doc->impl->add (dafb->field->impl);
+}
+
+lcn_error_t *
+lcn_document_add_field (lcn_document_t *doc, lcn_field_t *field)
+{
+  document_add_field_baton dafb;
+
+  dafb.doc = doc;
+  dafb.field = field;
+
+  return lcn__swallow_exception (document_add_field_internal, &dafb);
+}
+
+} // extern "C"

Added: incubator/lucene4c/branches/gcj-backend/src/document/document.hxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/document/document.hxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/document/document.hxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/document/document.hxx Sat May 21 16:20:19 2005
@@ -0,0 +1,30 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <org/apache/lucene/document/Document.h>
+
+#ifndef _DOCUMENT_HXX
+#define _DOCUMENT_HXX
+
+extern "C" {
+
+struct lcn_document_t {
+  org::apache::lucene::document::Document *impl;
+};
+
+} // extern "C"
+
+#endif // _DOCUMENT_HXX

Added: incubator/lucene4c/branches/gcj-backend/src/document/field.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/document/field.cxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/document/field.cxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/document/field.cxx Sat May 21 16:20:19 2005
@@ -0,0 +1,135 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <gcj/cni.h>
+
+#include <org/apache/lucene/document/Field.h>
+
+#include "lcn_field.h"
+
+#include "field.hxx"
+
+#include "../util/exception.h"
+
+using namespace org::apache::lucene::document;
+
+extern "C" {
+
+struct field_text_baton {
+  lcn_field_t **f;
+  const char *name;
+  const char *value;
+  apr_pool_t *pool;
+};
+
+static void
+field_text_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::Text (name, value);
+}
+
+lcn_error_t *
+lcn_field_text (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_text_internal, &ftb);
+}
+
+struct field_name_baton {
+  char **name;
+  const lcn_field_t *f;
+  apr_pool_t *pool;
+};
+
+static void
+field_name_internal (void *baton)
+{
+  field_name_baton *fnb = static_cast<field_name_baton *>(baton);
+
+  jstring name = fnb->f->impl->name ();
+
+  jsize length = JvGetStringUTFLength (name);
+
+  *fnb->name = static_cast<char *>(apr_pcalloc (fnb->pool, length + 1));
+
+  JvGetStringUTFRegion (name, 0, name->length(), *fnb->name);
+}
+
+lcn_error_t *
+lcn_field_name (char **name,
+                const lcn_field_t *f,
+                apr_pool_t *pool)
+{
+  field_name_baton fnb;
+
+  fnb.name = name;
+  fnb.f = f;
+  fnb.pool = pool;
+
+  return lcn__swallow_exception (field_name_internal, &fnb);
+}
+
+struct field_content_baton {
+  char **content;
+  const lcn_field_t *f;
+  apr_pool_t *pool;
+};
+
+static void
+field_content_internal (void *baton)
+{
+  field_content_baton *fcb = static_cast<field_content_baton *>(baton);
+
+  jstring content = fcb->f->impl->stringValue ();
+
+  jsize length = JvGetStringUTFLength (content);
+
+  *fcb->content = static_cast<char *>(apr_pcalloc (fcb->pool, length + 1));
+
+  JvGetStringUTFRegion (content, 0, content->length(), *fcb->content);
+}
+
+lcn_error_t *
+lcn_field_content (char **content,
+                   const lcn_field_t *f,
+                   apr_pool_t *pool)
+{
+  field_content_baton fcb;
+
+  fcb.content = content;
+  fcb.f = f;
+  fcb.pool = pool;
+
+  return lcn__swallow_exception (field_content_internal, &fcb);
+}
+} // extern "C"

Added: incubator/lucene4c/branches/gcj-backend/src/document/field.hxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/document/field.hxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/document/field.hxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/document/field.hxx Sat May 21 16:20:19 2005
@@ -0,0 +1,30 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <org/apache/lucene/document/Field.h>
+
+#ifndef _FIELD_HXX
+#define _FIELD_HXX
+
+extern "C" {
+
+struct lcn_field_t {
+  ::org::apache::lucene::document::Field *impl;
+};
+
+} // extern "C"
+
+#endif // _FIELD_HXX

Added: incubator/lucene4c/branches/gcj-backend/src/index/writer.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/index/writer.cxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/index/writer.cxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/index/writer.cxx Sat May 21 16:20:19 2005
@@ -0,0 +1,153 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <gcj/cni.h>
+
+#include <org/apache/lucene/index/IndexWriter.h>
+
+#include "lcn_index_writer.h"
+
+#include "../util/exception.h"
+
+#include "../analysis/analyzer.hxx"
+#include "../document/document.hxx"
+
+using namespace org::apache::lucene::index;
+
+extern "C" {
+
+struct lcn_index_writer_t {
+  IndexWriter *impl;
+};
+
+struct index_writer_make_baton {
+  lcn_index_writer_t **writer;
+  const char *path;
+  lcn_analyzer_t *analyzer;
+  bool create;
+  apr_pool_t *pool;
+};
+
+static apr_status_t
+run_close (void *b)
+{
+  lcn_index_writer_t *writer = static_cast<lcn_index_writer_t *>(b);
+
+  lcn_error_t *err = lcn_index_writer_close (writer);
+
+  if (err)
+    {
+      lcn_error_clear (err);
+
+      return APR_EGENERAL; // XXX better error...
+    }
+
+  return APR_SUCCESS;
+}
+
+static void
+index_writer_make_internal (void *b)
+{
+  index_writer_make_baton *iwcb = static_cast<index_writer_make_baton *>(b);
+
+  *iwcb->writer = static_cast<lcn_index_writer_t *>
+                    (apr_palloc (iwcb->pool, sizeof (lcn_index_writer_t)));
+
+  jstring path = JvNewStringUTF (iwcb->path);
+
+  (*iwcb->writer)->impl = new IndexWriter (path,
+                                           iwcb->analyzer->impl,
+                                           iwcb->create);
+
+  apr_pool_cleanup_register (iwcb->pool, *iwcb->writer, run_close, NULL);
+}
+
+lcn_error_t *
+lcn_index_writer_create (lcn_index_writer_t **writer,
+                         const char *path,
+                         lcn_analyzer_t *analyzer,
+                         apr_pool_t *pool)
+{
+  index_writer_make_baton iwmb;
+
+  iwmb.writer = writer;
+  iwmb.path = path;
+  iwmb.analyzer = analyzer;
+  iwmb.create = true;
+  iwmb.pool = pool;
+
+  return lcn__swallow_exception (index_writer_make_internal, &iwmb);
+}
+
+lcn_error_t *
+lcn_index_writer_open (lcn_index_writer_t **writer,
+                       const char *path,
+                       lcn_analyzer_t *analyzer,
+                       apr_pool_t *pool)
+{
+  index_writer_make_baton iwmb;
+
+  iwmb.writer = writer;
+  iwmb.path = path;
+  iwmb.analyzer = analyzer;
+  iwmb.create = false;
+  iwmb.pool = pool;
+
+  return lcn__swallow_exception (index_writer_make_internal, &iwmb);
+}
+
+struct index_writer_add_document_baton {
+  lcn_index_writer_t *writer;
+  lcn_document_t *document;
+};
+
+static void
+index_writer_add_document_internal (void *b)
+{
+  index_writer_add_document_baton *iwadb
+    = static_cast<index_writer_add_document_baton *>(b);
+
+  iwadb->writer->impl->addDocument (iwadb->document->impl);
+}
+
+lcn_error_t *
+lcn_index_writer_add_document (lcn_index_writer_t *writer,
+                               lcn_document_t *document,
+                               apr_pool_t *pool)
+{
+  index_writer_add_document_baton iwadb;
+
+  iwadb.writer = writer;
+  iwadb.document = document;
+
+  return lcn__swallow_exception (index_writer_add_document_internal, &iwadb);
+}
+
+static void
+index_writer_close_internal (void *b)
+{
+  lcn_index_writer_t *writer = static_cast<lcn_index_writer_t *>(b);
+
+  writer->impl->close ();
+}
+
+lcn_error_t *
+lcn_index_writer_close (lcn_index_writer_t *writer)
+{
+  return lcn__swallow_exception (index_writer_close_internal, writer);
+}
+
+} // extern "C"

Modified: incubator/lucene4c/branches/gcj-backend/src/util/error.c
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/util/error.c?rev=171264&r1=171263&r2=171264&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/util/error.c (original)
+++ incubator/lucene4c/branches/gcj-backend/src/util/error.c Sat May 21 16:20:19 2005
@@ -14,61 +14,22 @@
  * limitations under the License.
  */
 
-#include <stdlib.h>
-
 #include <apr_strings.h>
 
-#include "lcn_types.h"
-
-static lcn_error_t *
-make_error_internal (apr_status_t apr_err, lcn_error_t *child)
-{
-  apr_pool_t *pool;
-  lcn_error_t *new_error;
-
-  if (child)
-    pool = child->pool;
-  else
-    {
-      pool = lcn_pool_create (NULL);
-      if (! pool)
-        abort ();
-    }
-
-  new_error = apr_pcalloc (pool, sizeof (*new_error));
-
-  new_error->apr_err = apr_err;
-  new_error->child = child;
-  new_error->pool = pool;
-
-  return new_error;
-}
-
-lcn_error_t *
-lcn_error_create (apr_status_t apr_err, lcn_error_t *child, const char *msg)
-{
-  lcn_error_t *err = make_error_internal (apr_err, child);
-
-  if (msg)
-    err->message = apr_pstrdup (err->pool, msg);
-
-  return err;
-}
+#include "lcn_pools.h"
+#include "lcn_error.h"
 
 lcn_error_t *
-lcn_error_createf (apr_status_t apr_err,
-                   lcn_error_t *child,
-                   const char *fmt,
-                   ...)
+lcn_error_create (lcn_error_code_t code, const char *reason)
 {
-  lcn_error_t *err = make_error_internal (apr_err, child);
-  va_list ap;
+  apr_pool_t *pool = lcn_pool_create (NULL);
 
-  va_start (ap, fmt);
+  lcn_error_t *err = apr_palloc (pool, sizeof (*err));
 
-  err->message = apr_pvsprintf (err->pool, fmt, ap);
+  err->pool = pool;
+  err->code = code;
 
-  va_end (ap);
+  err->message = apr_pstrdup (pool, reason);
 
   return err;
 }
@@ -77,7 +38,5 @@
 lcn_error_clear (lcn_error_t *err)
 {
   if (err)
-    {
-      lcn_pool_destroy (err->pool);
-    }
+    lcn_pool_destroy (err->pool);
 }

Added: incubator/lucene4c/branches/gcj-backend/src/util/exception.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/util/exception.cxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/util/exception.cxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/util/exception.cxx Sat May 21 16:20:19 2005
@@ -0,0 +1,71 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as
+ * applicable.
+ *
+ * Licensed 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.
+ */
+
+#include <gcj/cni.h>
+
+#include <java/lang/RuntimeException.h>
+#include <java/lang/IllegalArgumentException.h>
+#include <java/io/IOException.h>
+
+using namespace java::lang;
+using namespace java::io;
+
+#include <apr_strings.h>
+
+#include "lcn_pools.h"
+
+#include "exception.h"
+
+extern "C" {
+
+static lcn_error_t *
+error_create (lcn_error_code_t code, const jstring reason)
+{
+  apr_pool_t *pool = lcn_pool_create (NULL);
+
+  lcn_error_t *err = static_cast<lcn_error_t *>(apr_palloc (pool,
+                                                            sizeof (*err)));
+  err->pool = pool;
+  err->code = code;
+
+  jsize length = JvGetStringUTFLength (reason);
+
+  err->message = static_cast<char *>(apr_palloc (pool, length + 1));
+
+  JvGetStringUTFRegion (reason,
+                        0,
+                        reason->length(),
+                        const_cast<char *>(err->message));
+  return err;
+}
+
+lcn_error_t *
+lcn__swallow_exception (lcn__swallow_func_t func, void *baton)
+{
+  try {
+    func (baton);
+  } catch (IOException *e) {
+    return error_create (LCN_IO_EXCEPTION, e->getMessage());
+  } catch (IllegalArgumentException *e) {
+    return error_create (LCN_ILLEGAL_ARGUMENT_EXCEPTION, e->getMessage());
+  } catch (RuntimeException *e) {
+    return error_create (LCN_RUNTIME_EXCEPTION, e->getMessage());
+  }
+
+  return LCN_NO_ERROR;
+}
+
+} // extern "C"

Added: incubator/lucene4c/branches/gcj-backend/src/util/exception.h
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/util/exception.h?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/util/exception.h (added)
+++ incubator/lucene4c/branches/gcj-backend/src/util/exception.h Sat May 21 16:20:19 2005
@@ -0,0 +1,22 @@
+#ifndef _LCN_EXCEPTION_H
+#define _LCN_EXCEPTION_H
+
+#include "lcn_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/** Callback function for use in @c lcn__swallow_exception. */
+typedef void (*lcn__swallow_func_t) (void *baton);
+
+/** Run @a func, passing it @a baton.  If any Java level exceptions are
+ * thrown, they will be converted into an @c lcn_error_t and returned. */
+lcn_error_t *
+lcn__swallow_exception (lcn__swallow_func_t func, void *baton);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _LCN_EXCEPTION_H */

Added: incubator/lucene4c/branches/gcj-backend/src/util/init.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/util/init.cxx?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/util/init.cxx (added)
+++ incubator/lucene4c/branches/gcj-backend/src/util/init.cxx Sat May 21 16:20:19 2005
@@ -0,0 +1,30 @@
+#include <gcj/cni.h>
+
+#include <org/apache/lucene/document/Field.h>
+
+extern "C" {
+
+void
+lcn_init (void)
+{
+  JvCreateJavaVM (NULL);
+
+  // force initialization of classes with static members that won't
+  // get initialized in java land before we try to use them from C++.
+
+  JvInitClass (&::org::apache::lucene::document::Field::class$);
+}
+
+void
+lcn_thread_attach (void)
+{
+  JvAttachCurrentThread (NULL, NULL);
+}
+
+void
+lcn_thread_detach (void)
+{
+  JvDetachCurrentThread ();
+}
+
+} // extern "C"

Propchange: incubator/lucene4c/branches/gcj-backend/test/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sat May 21 16:20:19 2005
@@ -1,4 +1,5 @@
 tests
+test
 .deps
 .dirstamp
 .libs

Added: incubator/lucene4c/branches/gcj-backend/test/main.c
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/test/main.c?rev=171264&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/test/main.c (added)
+++ incubator/lucene4c/branches/gcj-backend/test/main.c Sat May 21 16:20:19 2005
@@ -0,0 +1,61 @@
+#include <apr.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "lcn_init.h"
+#include "lcn_document.h"
+#include "lcn_pools.h"
+#include "lcn_index_writer.h"
+
+int
+main (int argc, char *argv[])
+{
+  apr_initialize ();
+
+  atexit (apr_terminate);
+
+  lcn_init ();
+
+  lcn_thread_attach ();
+
+  lcn_document_t *doc;
+  lcn_field_t *field;
+  lcn_error_t *err;
+
+  apr_pool_t *pool = lcn_pool_create (NULL);
+
+  err = lcn_document_create (&doc, pool);
+  if (err)
+    fprintf (stderr, "error creating document :(\n");
+
+  err = lcn_field_text (&field, "path", "foo", pool);
+  if (err)
+    fprintf (stderr, "error creating field: %s\n", err->message);
+
+  err = lcn_document_add_field (doc, field);
+  if (err)
+    fprintf (stderr, "error adding field to document :(\n");
+
+  lcn_analyzer_t *analyzer;
+
+  err = lcn_analyzer_standard_create (&analyzer, pool);
+  if (err)
+    fprintf (stderr, "error creating analyzer: %s\n", err->message);
+
+  lcn_index_writer_t *writer;
+
+  err = lcn_index_writer_create (&writer, "index", analyzer, pool);
+  if (err)
+    fprintf (stderr, "error creating index: %s\n", err->message);
+
+  err = lcn_index_writer_add_document (writer, doc, pool);
+  if (err)
+    fprintf (stderr, "error adding document to index: %s\n", err->message);
+
+  lcn_pool_destroy (pool);
+
+  lcn_thread_detach ();
+
+  return 0;
+}



Mime
View raw message