lucene-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roo...@apache.org
Subject svn commit: r178588 - in /incubator/lucene4c/branches/gcj-backend: Makefile src/org/apache/lucene4c/IndexSearcherHack.java src/search/index_searcher.cxx test/main.c
Date Thu, 26 May 2005 05:15:28 GMT
Author: rooneg
Date: Wed May 25 22:15:27 2005
New Revision: 178588

URL: http://svn.apache.org/viewcvs?rev=178588&view=rev
Log:
Add another "do this in Java-land because I don't understand why it
won't work in C++" hack, this time to let us cast a Searcher to an
IndexSearcher, so we can call close on it.

* src/search/index_searcher.cxx
  (lcn_index_searcher_close): call into IndexSearcherHack::close.

* src/org/apache/lucene4c/IndexSearcherHack.java: new file.

* test/main.c
  (main): add some code to exercise the search code.

* Makefile: build new IndexSearcherHack stuff.

Added:
    incubator/lucene4c/branches/gcj-backend/src/org/apache/lucene4c/IndexSearcherHack.java
Modified:
    incubator/lucene4c/branches/gcj-backend/Makefile
    incubator/lucene4c/branches/gcj-backend/src/search/index_searcher.cxx
    incubator/lucene4c/branches/gcj-backend/test/main.c

Modified: incubator/lucene4c/branches/gcj-backend/Makefile
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/Makefile?rev=178588&r1=178587&r2=178588&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/Makefile (original)
+++ incubator/lucene4c/branches/gcj-backend/Makefile Wed May 25 22:15:27 2005
@@ -19,6 +19,7 @@
      src/document/document.o \
      src/analysis/standard.o \
      src/org/apache/lucene4c/QueryParserHack.o \
+     src/org/apache/lucene4c/IndexSearcherHack.o \
      src/query_parser/query_parser.o \
      src/search/searcher.o \
      src/search/index_searcher.o \
@@ -34,12 +35,18 @@
 	$(JCC) $(INCLUDES) --classpath lib/lucene-1.4.3.jar -c $< -o $@
 
 %.class: %.java
-	javac --classpath lib/lucene-1.4.3.jar -d src $<
+	javac -classpath lib/lucene-1.4.3.jar -d src $<
 
-all: lib/liblucene4c.so test/test include/org/apache/lucene4c/QueryParserHack.h
+all: lib/liblucene4c.so 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
+
+include/org/apache/lucene4c/IndexSearcherHack.h: src/org/apache/lucene4c/IndexSearcherHack.class
+	$(JCCH) --classpath lib/lucene-1.4.3.jar:src org.apache.lucene4c.IndexSearcherHack -d include
+
+src/search/index_searcher.o: include/org/apache/lucene4c/IndexSearcherHack.h
+src/query_parser/query_parser.o: include/org/apache/lucene4c/QueryParserHack.h
 
 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

Added: incubator/lucene4c/branches/gcj-backend/src/org/apache/lucene4c/IndexSearcherHack.java
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/org/apache/lucene4c/IndexSearcherHack.java?rev=178588&view=auto
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/org/apache/lucene4c/IndexSearcherHack.java
(added)
+++ incubator/lucene4c/branches/gcj-backend/src/org/apache/lucene4c/IndexSearcherHack.java
Wed May 25 22:15:27 2005
@@ -0,0 +1,10 @@
+package org.apache.lucene4c;
+
+class IndexSearcherHack {
+  static void
+  close (org.apache.lucene.search.Searcher s)
+    throws java.io.IOException
+  {
+    ((org.apache.lucene.search.IndexSearcher) s).close();
+  }
+}

Modified: incubator/lucene4c/branches/gcj-backend/src/search/index_searcher.cxx
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/src/search/index_searcher.cxx?rev=178588&r1=178587&r2=178588&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/src/search/index_searcher.cxx (original)
+++ incubator/lucene4c/branches/gcj-backend/src/search/index_searcher.cxx Wed May 25 22:15:27
2005
@@ -16,10 +16,10 @@
 
 #include <gcj/cni.h>
 
-#include <java/lang/ClassCastException.h>
-
 #include <org/apache/lucene/search/IndexSearcher.h>
 
+#include "org/apache/lucene4c/IndexSearcherHack.h"
+
 #include "lcn_searcher.h"
 
 #include "../util/exception.h"
@@ -87,19 +87,7 @@
 {
   lcn_searcher_t *searcher = static_cast<lcn_searcher_t *>(b);
 
-  // XXX should be dynamic cast...
-  IndexSearcher *s = static_cast<IndexSearcher *>(searcher->impl);
-
-  if (s)
-    {
-      s->close ();
-    }
-  else
-    {
-      throw new ::java::lang::ClassCastException (
-        JvNewStringUTF ("can't cast impl to IndexSearcher")
-      );
-    }
+  ::org::apache::lucene4c::IndexSearcherHack::close (searcher->impl);
 }
 
 lcn_error_t *

Modified: incubator/lucene4c/branches/gcj-backend/test/main.c
URL: http://svn.apache.org/viewcvs/incubator/lucene4c/branches/gcj-backend/test/main.c?rev=178588&r1=178587&r2=178588&view=diff
==============================================================================
--- incubator/lucene4c/branches/gcj-backend/test/main.c (original)
+++ incubator/lucene4c/branches/gcj-backend/test/main.c Wed May 25 22:15:27 2005
@@ -7,6 +7,8 @@
 #include "lcn_document.h"
 #include "lcn_pools.h"
 #include "lcn_index_writer.h"
+#include "lcn_query_parser.h"
+#include "lcn_searcher.h"
 
 int
 main (int argc, char *argv[])
@@ -52,6 +54,31 @@
   err = lcn_index_writer_add_document (writer, doc, pool);
   if (err)
     fprintf (stderr, "error adding document to index: %s\n", err->message);
+
+  lcn_searcher_t *searcher;
+
+  err = lcn_index_searcher_open (&searcher, "test/data/index", pool);
+  if (err)
+    fprintf (stderr, "error opening searcher... %s\n", err->message);
+
+  err = lcn_field_text (&field, "contents", "lucene", pool);
+  if (err)
+    fprintf (stderr, "error creating field: %s\n", err->message);
+
+  lcn_query_t *query;
+
+  err = lcn_query_parse (&query, "foo", field, analyzer, pool);
+  if (err)
+    fprintf (stderr, "error parsing query\n");
+
+  apr_array_header_t *hits = NULL;
+
+  err = lcn_searcher_search (&hits, searcher, query, NULL, NULL, pool);
+  if (err)
+    fprintf (stderr, "error running search: %s\n", err->message);
+
+  if (hits)
+    printf ("got %d results\n", hits->nelts);
 
   lcn_pool_destroy (pool);
 



Mime
View raw message