Beispiel #1
0
bool
PolyLex_Next_IMP(PolyLexicon *self) {
    PolyLexiconIVARS *const ivars = PolyLex_IVARS(self);
    SegLexQueue *lex_q = ivars->lex_q;
    SegLexicon *top_seg_lexicon = (SegLexicon*)SegLexQ_Peek(lex_q);

    // Churn through queue items with equal terms.
    while (top_seg_lexicon != NULL) {
        Obj *const candidate = SegLex_Get_Term(top_seg_lexicon);
        if ((candidate && !ivars->term)
            || Obj_Compare_To(ivars->term, candidate) != 0
           ) {
            // Succeed if the next item in the queue has a different term.
            DECREF(ivars->term);
            ivars->term = Obj_Clone(candidate);
            return true;
        }
        else {
            SegLexicon *seg_lex = (SegLexicon*)SegLexQ_Pop(lex_q);
            DECREF(seg_lex);
            if (SegLex_Next(top_seg_lexicon)) {
                SegLexQ_Insert(lex_q, INCREF(top_seg_lexicon));
            }
            top_seg_lexicon = (SegLexicon*)SegLexQ_Peek(lex_q);
        }
    }

    // If queue is empty, iterator is finished.
    DECREF(ivars->term);
    ivars->term = NULL;
    return false;
}
Beispiel #2
0
void
PolyLex_Seek_IMP(PolyLexicon *self, Obj *target) {
    PolyLexiconIVARS *const ivars = PolyLex_IVARS(self);
    Vector *seg_lexicons = ivars->seg_lexicons;
    SegLexQueue *lex_q = ivars->lex_q;

    if (target == NULL) {
        PolyLex_Reset(self);
        return;
    }

    // Refresh the queue, set vars.
    S_refresh_lex_q(lex_q, seg_lexicons, target);
    SegLexicon *least = (SegLexicon*)SegLexQ_Peek(lex_q);
    DECREF(ivars->term);
    ivars->term = NULL;
    if (least) {
        Obj *least_term = SegLex_Get_Term(least);
        ivars->term = least_term ? Obj_Clone(least_term) : NULL;
    }

    // Scan up to the real target.
    do {
        if (ivars->term) {
            const int32_t comparison = Obj_Compare_To(ivars->term, target);
            if (comparison >= 0) { break; }
        }
    } while (PolyLex_Next(self));
}
Beispiel #3
0
RangeQuery*
RangeQuery_init(RangeQuery *self, const CharBuf *field, Obj *lower_term,
                Obj *upper_term, bool_t include_lower, bool_t include_upper) {
    Query_init((Query*)self, 0.0f);
    self->field          = CB_Clone(field);
    self->lower_term     = lower_term ? Obj_Clone(lower_term) : NULL;
    self->upper_term     = upper_term ? Obj_Clone(upper_term) : NULL;
    self->include_lower  = include_lower;
    self->include_upper  = include_upper;
    if (!upper_term && !lower_term) {
        DECREF(self);
        self = NULL;
        THROW(ERR, "Must supply at least one of 'upper_term' and 'lower_term'");
    }
    return self;
}
Beispiel #4
0
RangeQuery*
RangeQuery_init(RangeQuery *self, String *field, Obj *lower_term,
                Obj *upper_term, bool include_lower, bool include_upper) {
    Query_init((Query*)self, 0.0f);
    RangeQueryIVARS *const ivars = RangeQuery_IVARS(self);
    ivars->field          = Str_Clone(field);
    ivars->lower_term     = lower_term ? Obj_Clone(lower_term) : NULL;
    ivars->upper_term     = upper_term ? Obj_Clone(upper_term) : NULL;
    ivars->include_lower  = include_lower;
    ivars->include_upper  = include_upper;
    if (!upper_term && !lower_term) {
        DECREF(self);
        self = NULL;
        THROW(ERR, "Must supply at least one of 'upper_term' and 'lower_term'");
    }
    return self;
}
Beispiel #5
0
TermQuery*
TermQuery_init(TermQuery *self, String *field, Obj *term) {
    Query_init((Query*)self, 1.0f);
    TermQueryIVARS *const ivars = TermQuery_IVARS(self);
    ivars->field  = Str_Clone(field);
    ivars->term   = Obj_Clone(term);
    return self;
}
Beispiel #6
0
Obj*
Freezer_load(Obj *obj) {
    if (Obj_is_a(obj, HASH)) {
        return S_load_from_hash((Hash*)obj);
    }
    else if (Obj_is_a(obj, VECTOR)) {
        return S_load_from_array((Vector*)obj);
    }
    else {
        return Obj_Clone(obj);
    }
}
Beispiel #7
0
VArray*
VA_Clone_IMP(VArray *self) {
    VArray *twin = VA_new(self->size);

    // Clone each element.
    for (uint32_t i = 0; i < self->size; i++) {
        Obj *elem = self->elems[i];
        if (elem) {
            twin->elems[i] = Obj_Clone(elem);
        }
    }

    // Ensure that size is the same if NULL elems at end.
    twin->size = self->size;

    return twin;
}
void
SortFieldWriter_Add_IMP(SortFieldWriter *self, int32_t doc_id, Obj *value) {
    SortFieldWriterIVARS *const ivars = SortFieldWriter_IVARS(self);
    Counter *counter   = ivars->counter;
    Counter_Add(counter, ivars->mem_per_entry);
    if (ivars->prim_id == FType_TEXT) {
        int64_t size = Str_Get_Size((String*)value) + 1;
        size = SI_increase_to_word_multiple(size);
        Counter_Add(counter, size);
    }
    else if (ivars->prim_id == FType_BLOB) {
        int64_t size = Blob_Get_Size((Blob*)value) + 1;
        size = SI_increase_to_word_multiple(size);
        Counter_Add(counter, size);
    }
    SFWriterElem *elem = S_SFWriterElem_create(Obj_Clone(value), doc_id);
    SortFieldWriter_Feed(self, (Obj*)elem);
    ivars->count++;
}
Beispiel #9
0
Obj*
Freezer_dump(Obj *obj) {
    if (Obj_is_a(obj, STRING)) {
        return (Obj*)Obj_To_String(obj);
    }
    else if (Obj_is_a(obj, VECTOR)) {
        return S_dump_array((Vector*)obj);
    }
    else if (Obj_is_a(obj, HASH)) {
        return S_dump_hash((Hash*)obj);
    }
    else if (Obj_is_a(obj, ANALYZER)) {
        return Analyzer_Dump((Analyzer*)obj);
    }
    else if (Obj_is_a(obj, DOC)) {
        return (Obj*)Doc_Dump((Doc*)obj);
    }
    else if (Obj_is_a(obj, SIMILARITY)) {
        return Sim_Dump((Similarity*)obj);
    }
    else if (Obj_is_a(obj, FIELDTYPE)) {
        return FType_Dump((FieldType*)obj);
    }
    else if (Obj_is_a(obj, SCHEMA)) {
        return (Obj*)Schema_Dump((Schema*)obj);
    }
    else if (Obj_is_a(obj, QUERY)) {
        return Query_Dump((Query*)obj);
    }
    else if (Obj_is_a(obj, FLOAT)
             || Obj_is_a(obj, INTEGER)
             || Obj_is_a(obj, BOOLEAN)) {
        return Obj_Clone(obj);
    }
    else {
        return (Obj*)Obj_To_String(obj);
    }
}
Beispiel #10
0
static void
S_attempt_Clone(void *context) {
    Obj_Clone((Obj*)context);
}
Beispiel #11
0
Obj*
Hash_Make_Key_IMP(Hash *self, Obj *key, int32_t hash_sum) {
    UNUSED_VAR(self);
    UNUSED_VAR(hash_sum);
    return Obj_Clone(key);
}