Changeset 294d6fdf2503283b97bc859af2e7b875a85a6eea

Show
Ignore:
Timestamp:
04/23/08 20:21:34 (9 months ago)
Author:
David Balmain <dbalmain@…>
Parents:
8f9e905705f715e2dc4745a098e9a1819271873a
Children:
ac6c089c859ffd951ffd9839fd3ec6b1f8703a0b, af195088ac05210716bf17da06c341a7d5469e58
git-committer:
David Balmain <dbalmain@gmail.com> / 2008-04-23T20:21:34Z+1000
Message:

Updated Ruby bindings

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • c/src/ind.c

    r8f9e90 r294d6f  
    55 
    66 
    7 static const char * NON_UNIQUE_KEY_ERROR_MSG = "Tried to use a key that was not unique"; 
     7static const char *NON_UNIQUE_KEY_ERROR_MSG = 
     8    "Tried to use a key that was not unique"; 
    89 
    910static const char *ID_STRING = "id"; 
  • c/src/q_parser.c

    r8f9e90 r294d6f  
    21992199                 " was %s", buf, (char *)msg); 
    22002200    } 
     2201    while (qp->fields_top->next != NULL) { 
     2202        qp_pop_fields(qp); 
     2203    } 
    22012204    return 0; 
    22022205} 
     
    28592862void qp_destroy(QParser *self) 
    28602863{ 
    2861     hs_destroy(self->tokenized_fields); 
    2862     hs_destroy(self->def_fields); 
     2864    if (self->tokenized_fields != self->all_fields) { 
     2865        hs_destroy(self->tokenized_fields); 
     2866    } 
     2867    if (self->def_fields != self->all_fields) { 
     2868        hs_destroy(self->def_fields); 
     2869    } 
    28632870    hs_destroy(self->all_fields); 
    28642871 
     
    30473054    Query *volatile q = NULL; 
    30483055    qp->recovering = true; 
     3056    assert(qp->fields_top->next == NULL); 
    30493057    FLDS(q, get_term_q(qp, field, str)); 
    30503058    return q; 
  • c/src/q_parser.y

    r8f9e90 r294d6f  
    462462                 " was %s", buf, (char *)msg); 
    463463    } 
     464    while (qp->fields_top->next != NULL) { 
     465        qp_pop_fields(qp); 
     466    } 
    464467    return 0; 
    465468} 
     
    11221125void qp_destroy(QParser *self) 
    11231126{ 
    1124     hs_destroy(self->tokenized_fields); 
    1125     hs_destroy(self->def_fields); 
     1127    if (self->tokenized_fields != self->all_fields) { 
     1128        hs_destroy(self->tokenized_fields); 
     1129    } 
     1130    if (self->def_fields != self->all_fields) { 
     1131        hs_destroy(self->def_fields); 
     1132    } 
    11261133    hs_destroy(self->all_fields); 
    11271134 
     
    13101317    Query *volatile q = NULL; 
    13111318    qp->recovering = true; 
     1319    assert(qp->fields_top->next == NULL); 
    13121320    FLDS(q, get_term_q(qp, field, str)); 
    13131321    return q; 
  • c/test/test_q_parser.c

    r8f9e90 r294d6f  
    7575        {"()", ""}, 
    7676        {"field:()", ""}, 
     77        {"one AND (f1:two OR f2:three) AND four", 
     78            "+one +(f1:two f2:three) +four"}, 
    7779        {"xx:\"Hello Newman\" field:()", "\"hello newman\" ()"}, 
    7880        {"one (two AND three)", "one (+two +three)"}, 
  • ruby/ext/r_qparser.c

    r399100 r294d6f  
    5353    if (rfields == Qnil) return NULL; 
    5454 
    55     fields = hs_new_str(NULL); 
     55    fields = hs_new_ptr(NULL); 
    5656    if (TYPE(rfields) == T_ARRAY) { 
    5757        int i; 
     
    7777    } 
    7878    return fields; 
     79} 
     80 
     81static void 
     82hs_safe_merge(HashSet *merger, HashSet *mergee) 
     83{ 
     84    HashSetEntry *hse; 
     85    for (hse = mergee->first; hse; hse = hse->next) { 
     86        hs_add(merger, (char *)hse->elem); 
     87    } 
    7988} 
    8089 
     
    177186    } 
    178187    if (all_fields == NULL) { 
    179         all_fields = hs_new_str(NULL); 
     188        all_fields = hs_new_ptr(NULL); 
    180189    } 
    181190 
     
    184193    } 
    185194 
    186     qp = qp_new(all_fields, def_fields, tkz_fields, analyzer); 
     195    qp = qp_new(analyzer); 
     196    hs_destroy(qp->all_fields); 
     197    hs_destroy(qp->def_fields); 
     198    //hs_destroy(qp->tokenized_fields); 
     199 
     200    if (def_fields) hs_safe_merge(all_fields, def_fields); 
     201    if (tkz_fields) hs_safe_merge(all_fields, tkz_fields); 
     202    qp->all_fields = all_fields; 
     203    qp->def_fields = def_fields ? def_fields : all_fields; 
     204    qp->tokenized_fields = tkz_fields ? tkz_fields : all_fields; 
     205    qp->fields_top->fields = def_fields; 
     206 
    187207    qp->allow_any_fields = true; 
    188208    qp->clean_str = true; 
     
    286306    HashSet *fields = frb_get_fields(rfields); 
    287307 
    288     if (qp->def_fields == qp->all_fields) { 
    289         qp->def_fields = NULL; 
    290     } 
     308    /* if def_fields == all_fields then we need to replace both */ 
     309    if (qp->def_fields == qp->all_fields) qp->def_fields = NULL; 
     310    if (qp->tokenized_fields == qp->all_fields) qp->tokenized_fields = NULL; 
     311 
    291312    if (fields == NULL) { 
    292         fields = hs_new_str(NULL); 
    293     } 
     313        fields = hs_new_ptr(NULL); 
     314    } 
     315 
     316    /* make sure all the fields in tokenized fields are contained in 
     317     * all_fields */ 
     318    if (qp->tokenized_fields) hs_safe_merge(fields, qp->tokenized_fields); 
     319 
     320    /* delete old fields set */ 
     321    assert(qp->all_fields->free_elem_i == dummy_free); 
    294322    hs_destroy(qp->all_fields); 
     323 
     324    /* add the new fields set and add to def_fields if necessary */ 
    295325    qp->all_fields = fields; 
    296326    if (qp->def_fields == NULL) { 
    297327        qp->def_fields = fields; 
    298     } 
     328        qp->fields_top->fields = fields; 
     329    } 
     330    if (qp->tokenized_fields == NULL) qp->tokenized_fields = fields; 
    299331 
    300332    return self; 
     
    338370{ 
    339371    GET_QP; 
    340     if (qp->tokenized_fields) hs_destroy(qp->tokenized_fields); 
     372    if (qp->tokenized_fields != qp->all_fields) { 
     373        hs_destroy(qp->tokenized_fields); 
     374    } 
    341375    qp->tokenized_fields = frb_get_fields(rfields); 
    342376    return self;