Author: rooneg
Date: Sat Mar 19 19:14:34 2005
New Revision: 158284

URL: http://svn.apache.org/viewcvs?view=rev&rev=158284
Log:
Start adding in the lcn_weight_t interface, which will allow the scorer
code to become more similar to the Java implementation, and thus easier
to get right.  So far the lcn_weight_t interface is just a pass through
to the underlying lcn_query_t, but that will change soon enough.

* include/lcn_scorer.h
  (lcn_query_t): move declaration of this to...

* include/lcn_query.h
  (lcn_query_t): here.  it's no longer needed by the scorer header.
  (lcn_weight_t): new forward declaration.
  (lcn_weight_query): function to return the weight's underlying query.
  (lcn_weight_value,
   lcn_weight_sum_of_squared_weights,
   lcn_weight_normalize): ifdefed out prototypes, haven't implemented
   them yet.
  (lcn_query_weight): function to create a weight from a query.
  (lcn_query_scorer): rename to...
  (lcn_weight_scorer): this.  now takes a weight, not a query.

* src/search/query.c
  (lcn_weight_t): pass through impl, just holds the query for now.
  (lcn_query_weight): dummy impl, just allocates a weight and stashes
   the underlying query.
  (lcn_query_scorer): renamed to...
  (lcn_weight_scorer): this, just pulls out the query from the weight
   for now.

* src/search/scorer.c
  (fill_scorers_array): create weights for each query before calling
   lcn_weight_scorer.

* src/cmdline/main.c
  (lcn_search_cmd): create a weight so we can call lcn_weight_scorer.

* test/search/scorer_test.c
  (test_term_scorer,
   test_boolean_scorer): use the new lcn_weight_scorer interface.

Modified:
    incubator/lucene4c/trunk/include/lcn_query.h
    incubator/lucene4c/trunk/include/lcn_scorer.h
    incubator/lucene4c/trunk/src/cmdline/main.c
    incubator/lucene4c/trunk/src/search/query.c
    incubator/lucene4c/trunk/src/search/scorer.c
    incubator/lucene4c/trunk/test/search/scorer_test.c

Modified: incubator/lucene4c/trunk/include/lcn_query.h
URL: 
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/include/lcn_query.h?view=diff&r1=158283&r2=158284
==============================================================================
--- incubator/lucene4c/trunk/include/lcn_query.h (original)
+++ incubator/lucene4c/trunk/include/lcn_query.h Sat Mar 19 19:14:34 2005
@@ -30,6 +30,9 @@
 extern "C" {
 #endif /* __cplusplus */
 
+/** 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,
@@ -64,7 +67,33 @@
                        lcn_query_t *clause,
                        lcn_boolean_clause_occur_t occur);
 
-/** Return a @a scorer for @a query run over @a index, allocated in
+/** The structure that stores data about a query that must be modified
+ * during a search. This allows a given query to be reused for more than
+ * one search.
+ */
+typedef struct lcn_weight_t lcn_weight_t;
+
+/** Return @a weight's underlying query. */
+lcn_query_t * lcn_weight_query (lcn_weight_t *weight);
+
+#if NOTYET
+float lcn_weight_value (lcn_weight_t *weight);
+
+lcn_error_t *
+lcn_weight_sum_of_squared_weights (float *sum, lcn_weight_t *weight);
+
+lcn_error_t * lcn_weight_normalize (lcn_weight_t *weight, float norm);
+
+/* XXX leaving out lcn_weight_explain for now... */
+#endif
+
+/** Create an @a weight from @a query. */
+lcn_error_t *
+lcn_query_weight (lcn_weight_t **weight,
+                  lcn_query_t *query,
+                  apr_pool_t *pool);
+
+/** Return a @a scorer for @a weight run over @a index, allocated in
  * @a pool.
  *
  * @note the Java Lucene version of this stuff works on a Weight, not a
@@ -72,10 +101,10 @@
  * a Query, so we can make that split later.
  */
 lcn_error_t *
-lcn_query_scorer (lcn_scorer_t **scorer,
-                  lcn_query_t *query,
-                  lcn_index_t *index,
-                  apr_pool_t *pool);
+lcn_weight_scorer (lcn_scorer_t **scorer,
+                   lcn_weight_t *weight,
+                   lcn_index_t *index,
+                   apr_pool_t *pool);
 
 #ifdef __cplusplus
 }

Modified: incubator/lucene4c/trunk/include/lcn_scorer.h
URL: 
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/include/lcn_scorer.h?view=diff&r1=158283&r2=158284
==============================================================================
--- incubator/lucene4c/trunk/include/lcn_scorer.h (original)
+++ incubator/lucene4c/trunk/include/lcn_scorer.h Sat Mar 19 19:14:34 2005
@@ -32,13 +32,6 @@
 /** Abstract scorer object. */
 typedef struct lcn_scorer_t lcn_scorer_t;
 
-/** Abstract query object.
- *
- * This is declared here to avoid problems with circular dependencies
- * between queries and scorers.
- */
-typedef struct lcn_query_t lcn_query_t;
-
 /** Create a @a scorer that returns scores for each document matched
  * in @a iter, allocated in @a pool.
  */

Modified: incubator/lucene4c/trunk/src/cmdline/main.c
URL: 
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/cmdline/main.c?view=diff&r1=158283&r2=158284
==============================================================================
--- incubator/lucene4c/trunk/src/cmdline/main.c (original)
+++ incubator/lucene4c/trunk/src/cmdline/main.c Sat Mar 19 19:14:34 2005
@@ -176,6 +176,7 @@
       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;
       lcn_query_t *query;
       lcn_index_t *idx;
@@ -194,8 +195,9 @@
                                        lcn_str_from_cstring (argv[1], pool),
                                        pool));
 
-      /* XXX eventually we want to use a searcher, not a scorer. */
-      LCN_ERR (lcn_query_scorer (&scorer, query, idx, pool));
+      LCN_ERR (lcn_query_weight (&weight, query, pool));
+
+      LCN_ERR (lcn_weight_scorer (&scorer, weight, idx, pool));
 
       LCN_ERR (print_doc_field (idx,
                                 lcn_scorer_doc (scorer),

Modified: incubator/lucene4c/trunk/src/search/query.c
URL: 
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/search/query.c?view=diff&r1=158283&r2=158284
==============================================================================
--- incubator/lucene4c/trunk/src/search/query.c (original)
+++ incubator/lucene4c/trunk/src/search/query.c Sat Mar 19 19:14:34 2005
@@ -139,11 +139,37 @@
   return LCN_NO_ERROR;
 }
 
+struct lcn_weight_t {
+  lcn_query_t *query;
+
+  void *baton;
+};
+
+lcn_query_t *
+lcn_weight_query (lcn_weight_t *weight)
+{
+  return weight->query;
+}
+
+lcn_error_t *
+lcn_query_weight (lcn_weight_t **weight, lcn_query_t *query, apr_pool_t *pool)
+{
+  lcn_weight_t *w = apr_pcalloc (pool, sizeof (*w));
+
+  w->query = query;
+
+  *weight = w;
+
+  return LCN_NO_ERROR;
+}
+
 lcn_error_t *
-lcn_query_scorer (lcn_scorer_t **scorer,
-                  lcn_query_t *query,
-                  lcn_index_t *index,
-                  apr_pool_t *pool)
+lcn_weight_scorer (lcn_scorer_t **scorer,
+                   lcn_weight_t *weight,
+                   lcn_index_t *index,
+                   apr_pool_t *pool)
 {
+  lcn_query_t *query = lcn_weight_query (weight);
+
   return query->scorer_internal (scorer, query, index, pool);
 }

Modified: incubator/lucene4c/trunk/src/search/scorer.c
URL: 
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/src/search/scorer.c?view=diff&r1=158283&r2=158284
==============================================================================
--- incubator/lucene4c/trunk/src/search/scorer.c (original)
+++ incubator/lucene4c/trunk/src/search/scorer.c Sat Mar 19 19:14:34 2005
@@ -289,11 +289,16 @@
   for (i = 0; i < query_array->nelts; ++i)
     {
       lcn_scorer_t *scorer;
-      
-      LCN_ERR (lcn_query_scorer (&scorer,
-                                 APR_ARRAY_IDX (query_array, i, lcn_query_t *),
-                                 index,
-                                 pool));
+      lcn_weight_t *weight;
+
+      lcn_query_t *query = APR_ARRAY_IDX (query_array, i, lcn_query_t *);
+
+      LCN_ERR (lcn_query_weight (&weight, query, pool));
+
+      LCN_ERR (lcn_weight_scorer (&scorer,
+                                  weight,
+                                  index,
+                                  pool));
 
       APR_ARRAY_PUSH (scorer_array, lcn_scorer_t *) = scorer;
     }

Modified: incubator/lucene4c/trunk/test/search/scorer_test.c
URL: 
http://svn.apache.org/viewcvs/incubator/lucene4c/trunk/test/search/scorer_test.c?view=diff&r1=158283&r2=158284
==============================================================================
--- incubator/lucene4c/trunk/test/search/scorer_test.c (original)
+++ incubator/lucene4c/trunk/test/search/scorer_test.c Sat Mar 19 19:14:34 2005
@@ -25,6 +25,7 @@
 test_term_scorer (abts_case *tc, void *data)
 {
   lcn_query_t *query;
+  lcn_weight_t *weight;
   lcn_boolean_t next;
   lcn_scorer_t *scorer;
   lcn_index_t *index;
@@ -39,7 +40,9 @@
                                                            p),
                                   p));
 
-  CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+  CHK_ERR (lcn_query_weight (&weight, query, p));
+
+  CHK_ERR (lcn_weight_scorer (&scorer, weight, index, p));
 
   ABTS_INT_EQUAL (tc, 1, lcn_scorer_doc (scorer));
 
@@ -68,6 +71,7 @@
 test_boolean_scorer (abts_case *tc, void *data)
 {
   lcn_query_t *query, *tquery;
+  lcn_weight_t *weight;
   lcn_scorer_t *scorer;
   lcn_boolean_t next;
   lcn_index_t *index;
@@ -78,8 +82,10 @@
 
   CHK_ERR (lcn_boolean_query_create (&query, p));
 
+  CHK_ERR (lcn_query_weight (&weight, query, p));
+
   /* should fail if we don't have any queries added */
-  err = lcn_query_scorer (&scorer, query, index, p);
+  err = lcn_weight_scorer (&scorer, weight, index, p);
 
   ABTS_PTR_NOTNULL (tc, err);
 
@@ -95,8 +101,10 @@
 
   CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
 
+  CHK_ERR (lcn_query_weight (&weight, query, p));
+
   /* at this point results should be identical to just using the term query. */
-  CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+  CHK_ERR (lcn_weight_scorer (&scorer, weight, index, p));
 
   ABTS_INT_EQUAL (tc, 1, lcn_scorer_doc (scorer));
 
@@ -124,8 +132,10 @@
 
   CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
 
+  CHK_ERR (lcn_query_weight (&weight, query, p));
+
   /* now we should get results that contain both 'lucene' 'cutting' */
-  CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+  CHK_ERR (lcn_weight_scorer (&scorer, weight, index, p));
 
   ABTS_INT_EQUAL (tc, 40, lcn_scorer_doc (scorer));
 
@@ -165,7 +175,9 @@
 
   CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_SHOULD));
 
-  CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+  CHK_ERR (lcn_query_weight (&weight, query, p));
+
+  CHK_ERR (lcn_weight_scorer (&scorer, weight, index, p));
 
   ABTS_INT_EQUAL (tc, 1, lcn_scorer_doc (scorer));
 
@@ -201,7 +213,9 @@
 
   CHK_ERR (lcn_boolean_query_add (query, tquery, LCN_MUST));
 
-  CHK_ERR (lcn_query_scorer (&scorer, query, index, p));
+  CHK_ERR (lcn_query_weight (&weight, query, p));
+
+  CHK_ERR (lcn_weight_scorer (&scorer, weight, index, p));
 
   count = 1;
 


Reply via email to