lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] [01/17] git commit: refs/heads/cfish-string-prep1 - Rework Doc_Extract
Date Fri, 13 Sep 2013 18:31:33 GMT
Updated Branches:
  refs/heads/cfish-string-prep1 b0f30521d -> 0f10d5af2


Rework Doc_Extract

Remove the ViewCharBuf argument and return an incremented object.


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/b1fe3f66
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/b1fe3f66
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/b1fe3f66

Branch: refs/heads/cfish-string-prep1
Commit: b1fe3f6633cedf0c40ca0e7520f6faa5aa365938
Parents: 54ffcca
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Sat Sep 7 21:08:25 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Mon Sep 9 20:17:51 2013 +0200

----------------------------------------------------------------------
 c/sample/getting_started.c           |  3 ++-
 c/src/Lucy/Document/Doc.c            | 10 ++--------
 core/Lucy/Document/Doc.cfh           |  4 ++--
 core/Lucy/Highlight/Highlighter.c    | 21 +++++++++++----------
 core/Lucy/Test/Plan/TestFieldMisc.c  |  4 ++--
 core/Lucy/Test/Search/TestSortSpec.c |  4 ++--
 perl/xs/Lucy/Document/Doc.c          |  8 +++-----
 7 files changed, 24 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/c/sample/getting_started.c
----------------------------------------------------------------------
diff --git a/c/sample/getting_started.c b/c/sample/getting_started.c
index b4f697e..2816a30 100644
--- a/c/sample/getting_started.c
+++ b/c/sample/getting_started.c
@@ -174,10 +174,11 @@ S_search(IndexSearcher *searcher, const char *query) {
 
     // Loop over search results.
     while (NULL != (hit = Hits_Next(hits))) {
-        String *value_str = (String*)HitDoc_Extract(hit, field_str, NULL);
+        String *value_str = (String*)HitDoc_Extract(hit, field_str);
 
         printf("Result %d: %s\n", i, Str_Get_Ptr8(value_str));
 
+        DECREF(value_str);
         DECREF(hit);
         i++;
     }

http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/c/src/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/c/src/Lucy/Document/Doc.c b/c/src/Lucy/Document/Doc.c
index 8a682b7..e162839 100644
--- a/c/src/Lucy/Document/Doc.c
+++ b/c/src/Lucy/Document/Doc.c
@@ -85,15 +85,9 @@ Doc_Deserialize_IMP(Doc *self, InStream *instream) {
 }
 
 Obj*
-Doc_Extract_IMP(Doc *self, String *field, ViewCharBuf *target) {
+Doc_Extract_IMP(Doc *self, String *field) {
     Hash *hash = (Hash*)Doc_IVARS(self)->fields;
-    Obj  *obj  = Hash_Fetch(hash, (Obj *)field);
-
-    if (target && obj && Obj_Is_A(obj, STRING)) {
-        ViewCB_Assign(target, (String *)obj);
-    }
-
-    return obj;
+    return INCREF(Hash_Fetch(hash, (Obj *)field));
 }
 
 void*

http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/core/Lucy/Document/Doc.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Document/Doc.cfh b/core/Lucy/Document/Doc.cfh
index b7dc120..973f249 100644
--- a/core/Lucy/Document/Doc.cfh
+++ b/core/Lucy/Document/Doc.cfh
@@ -73,8 +73,8 @@ public class Lucy::Document::Doc inherits Clownfish::Obj {
      * return the interior object.  Callers must check to verify the kind of
      * object returned.
      */
-    nullable Obj*
-    Extract(Doc *self, String *field, ViewCharBuf *target);
+    nullable incremented Obj*
+    Extract(Doc *self, String *field);
 
     /* Unimplemented methods.
      */

http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/core/Lucy/Highlight/Highlighter.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Highlight/Highlighter.c b/core/Lucy/Highlight/Highlighter.c
index 637fd81..31759da 100644
--- a/core/Lucy/Highlight/Highlighter.c
+++ b/core/Lucy/Highlight/Highlighter.c
@@ -152,16 +152,15 @@ Highlighter_Get_Excerpt_Length_IMP(Highlighter *self) {
 String*
 Highlighter_Create_Excerpt_IMP(Highlighter *self, HitDoc *hit_doc) {
     HighlighterIVARS *const ivars = Highlighter_IVARS(self);
-    StackString *field_val
-        = (StackString*)HitDoc_Extract(hit_doc, ivars->field,
-                                         (ViewCharBuf*)SStr_BLANK());
+    String *field_val = (String*)HitDoc_Extract(hit_doc, ivars->field);
+    String *retval;
 
     if (!field_val || !Obj_Is_A((Obj*)field_val, STRING)) {
-        return NULL;
+        retval = NULL;
     }
-    else if (!SStr_Get_Size(field_val)) {
+    else if (!Str_Get_Size(field_val)) {
         // Empty string yields empty string.
-        return Str_new(0);
+        retval = Str_new(0);
     }
     else {
         DocVector *doc_vec
@@ -177,19 +176,21 @@ Highlighter_Create_Excerpt_IMP(Highlighter *self, HitDoc *hit_doc) {
 
         int32_t top;
         String *raw_excerpt
-            = Highlighter_Raw_Excerpt(self, (String*)field_val, &top,
-                                      heat_map);
+            = Highlighter_Raw_Excerpt(self, field_val, &top, heat_map);
         String *highlighted
             = Highlighter_Highlight_Excerpt(self, score_spans, raw_excerpt,
                                             top);
 
+        DECREF(raw_excerpt);
         DECREF(heat_map);
         DECREF(score_spans);
         DECREF(doc_vec);
-        DECREF(raw_excerpt);
 
-        return highlighted;
+        retval = highlighted;
     }
+
+    DECREF(field_val);
+    return retval;
 }
 
 static int32_t

http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/core/Lucy/Test/Plan/TestFieldMisc.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Plan/TestFieldMisc.c b/core/Lucy/Test/Plan/TestFieldMisc.c
index 1717c78..8414170 100644
--- a/core/Lucy/Test/Plan/TestFieldMisc.c
+++ b/core/Lucy/Test/Plan/TestFieldMisc.c
@@ -133,10 +133,10 @@ S_check(TestBatchRunner *runner, RAMFolder *folder, String *field,
     // Don't check the contents of the hit if there aren't any.
     if (expected_num_hits) {
         HitDoc *hit = Hits_Next(hits);
-        ViewCharBuf *value = (ViewCharBuf*)SStr_BLANK();
-        HitDoc_Extract(hit, field, value);
+        String *value = (String*)HitDoc_Extract(hit, field);
         TEST_TRUE(runner, Str_Equals(united_states_str, (Obj*)value),
                   "%s correct doc returned", Str_Get_Ptr8(field));
+        DECREF(value);
         DECREF(hit);
     }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/core/Lucy/Test/Search/TestSortSpec.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Search/TestSortSpec.c b/core/Lucy/Test/Search/TestSortSpec.c
index ead2c3f..ed6b945 100644
--- a/core/Lucy/Test/Search/TestSortSpec.c
+++ b/core/Lucy/Test/Search/TestSortSpec.c
@@ -351,11 +351,11 @@ S_test_sorted_search(IndexSearcher *searcher, String *query,
     Hits *hits = IxSearcher_Hits(searcher, (Obj*)query, 0, num_wanted, spec);
 
     VArray *results = VA_new(10);
-    ViewCharBuf *name = (ViewCharBuf*)SStr_BLANK();
     HitDoc *hit_doc;
     while (NULL != (hit_doc = Hits_Next(hits))) {
-        HitDoc_Extract(hit_doc, name_str, name);
+        String *name = (String*)HitDoc_Extract(hit_doc, name_str);
         VA_Push(results, (Obj*)Str_Clone((String*)name));
+        DECREF(name);
         DECREF(hit_doc);
     }
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/b1fe3f66/perl/xs/Lucy/Document/Doc.c
----------------------------------------------------------------------
diff --git a/perl/xs/Lucy/Document/Doc.c b/perl/xs/Lucy/Document/Doc.c
index 74243ec..224f0bb 100644
--- a/perl/xs/Lucy/Document/Doc.c
+++ b/perl/xs/Lucy/Document/Doc.c
@@ -143,8 +143,7 @@ LUCY_Doc_Deserialize_IMP(lucy_Doc *self, lucy_InStream *instream) {
 }
 
 cfish_Obj*
-LUCY_Doc_Extract_IMP(lucy_Doc *self, cfish_String *field,
-                     cfish_ViewCharBuf *target) {
+LUCY_Doc_Extract_IMP(lucy_Doc *self, cfish_String *field) {
     lucy_DocIVARS *const ivars = lucy_Doc_IVARS(self);
     cfish_Obj *retval = NULL;
     SV **sv_ptr = hv_fetch((HV*)ivars->fields, (char*)CFISH_Str_Get_Ptr8(field),
@@ -154,13 +153,12 @@ LUCY_Doc_Extract_IMP(lucy_Doc *self, cfish_String *field,
         SV *const sv = *sv_ptr;
         if (sv_isobject(sv) && sv_derived_from(sv, "Clownfish::Obj")) {
             IV tmp = SvIV(SvRV(sv));
-            retval = INT2PTR(cfish_Obj*, tmp);
+            retval = CFISH_INCREF(INT2PTR(cfish_Obj*, tmp));
         }
         else {
             STRLEN size;
             char *ptr = SvPVutf8(sv, size);
-            CFISH_ViewCB_Assign_Str(target, ptr, size);
-            retval = (cfish_Obj*)target;
+            retval = (cfish_Obj*)cfish_ViewCB_new_from_trusted_utf8(ptr, size);
         }
     }
 


Mime
View raw message