Beispiel #1
0
int32_t
Inverter_Next_IMP(Inverter *self) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    ivars->current = (InverterEntry*)VA_Fetch(ivars->entries, ++ivars->tick);
    if (!ivars->current) { ivars->current = ivars->blank; } // Exhausted.
    return InvEntry_IVARS(ivars->current)->field_num;
}
Beispiel #2
0
void
Inverter_Add_Field_IMP(Inverter *self, InverterEntry *entry) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    InverterEntryIVARS *const entry_ivars = InvEntry_IVARS(entry);

    // Get an Inversion, going through analyzer if appropriate.
    if (entry_ivars->analyzer) {
        DECREF(entry_ivars->inversion);
        entry_ivars->inversion
            = Analyzer_Transform_Text(entry_ivars->analyzer,
                                      (String*)entry_ivars->value);
        Inversion_Invert(entry_ivars->inversion);
    }
    else if (entry_ivars->indexed || entry_ivars->highlightable) {
        String *value = (String*)entry_ivars->value;
        size_t token_len = Str_Get_Size(value);
        Token *seed = Token_new(Str_Get_Ptr8(value),
                                token_len, 0, token_len, 1.0f, 1);
        DECREF(entry_ivars->inversion);
        entry_ivars->inversion = Inversion_new(seed);
        DECREF(seed);
        Inversion_Invert(entry_ivars->inversion); // Nearly a no-op.
    }

    // Prime the iterator.
    VA_Push(ivars->entries, INCREF(entry));
    ivars->sorted = false;
}
Beispiel #3
0
uint32_t
Inverter_Iterate_IMP(Inverter *self) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    ivars->tick = -1;
    if (!ivars->sorted) {
        VA_Sort(ivars->entries, NULL, NULL);
        ivars->sorted = true;
    }
    return VA_Get_Size(ivars->entries);
}
Beispiel #4
0
void
Inverter_Destroy_IMP(Inverter *self) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    Inverter_Clear(self);
    DECREF(ivars->blank);
    DECREF(ivars->entries);
    DECREF(ivars->entry_pool);
    DECREF(ivars->schema);
    DECREF(ivars->segment);
    SUPER_DESTROY(self, INVERTER);
}
Beispiel #5
0
void
Inverter_Clear_IMP(Inverter *self) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    for (uint32_t i = 0, max = VA_Get_Size(ivars->entries); i < max; i++) {
        InvEntry_Clear(VA_Fetch(ivars->entries, i));
    }
    VA_Clear(ivars->entries);
    ivars->tick = -1;
    DECREF(ivars->doc);
    ivars->doc = NULL;
}
Beispiel #6
0
void
Inverter_Invert_Doc_IMP(Inverter *self, Doc *doc) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    Hash *const fields = (Hash*)Doc_Get_Fields(doc);

    // Prepare for the new doc.
    Inverter_Set_Doc(self, doc);

    // Extract and invert the doc's fields.
    HashIterator *iter = HashIter_new(fields);
    while (HashIter_Next(iter)) {
        String *field = HashIter_Get_Key(iter);
        Obj    *obj   = HashIter_Get_Value(iter);

        InverterEntry *inventry = S_fetch_entry(ivars, field);
        InverterEntryIVARS *inventry_ivars = InvEntry_IVARS(inventry);
        FieldType *type = inventry_ivars->type;

        // Get the field value.
        switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) {
            case FType_TEXT: {
                    CERTIFY(obj, STRING);
                    break;
                }
            case FType_BLOB: {
                    CERTIFY(obj, BLOB);
                    break;
                }
            case FType_INT32:
            case FType_INT64: {
                    CERTIFY(obj, INTEGER);
                    break;
                }
            case FType_FLOAT32:
            case FType_FLOAT64: {
                    CERTIFY(obj, FLOAT);
                    break;
                }
            default:
                THROW(ERR, "Unrecognized type: %o", type);
        }

        if (inventry_ivars->value != obj) {
            DECREF(inventry_ivars->value);
            inventry_ivars->value = INCREF(obj);
        }

        Inverter_Add_Field(self, inventry);
    }
    DECREF(iter);
}
Beispiel #7
0
Inverter*
Inverter_init(Inverter *self, Schema *schema, Segment *segment) {
    InverterIVARS *const ivars = Inverter_IVARS(self);

    // Init.
    ivars->tick       = -1;
    ivars->doc        = NULL;
    ivars->sorted     = false;
    ivars->blank      = InvEntry_new(NULL, NULL, 0);
    ivars->current    = ivars->blank;

    // Derive.
    ivars->entry_pool = VA_new(Schema_Num_Fields(schema));
    ivars->entries    = VA_new(Schema_Num_Fields(schema));

    // Assign.
    ivars->schema  = (Schema*)INCREF(schema);
    ivars->segment = (Segment*)INCREF(segment);

    return self;
}
Beispiel #8
0
void
Inverter_Set_Boost_IMP(Inverter *self, float boost) {
    Inverter_IVARS(self)->boost = boost;
}
Beispiel #9
0
Similarity*
Inverter_Get_Similarity_IMP(Inverter *self) {
    InverterEntry *current = Inverter_IVARS(self)->current;
    return InvEntry_IVARS(current)->sim;
}
Beispiel #10
0
Analyzer*
Inverter_Get_Analyzer_IMP(Inverter *self) {
    InverterEntry *current = Inverter_IVARS(self)->current;
    return InvEntry_IVARS(current)->analyzer;
}
Beispiel #11
0
FieldType*
Inverter_Get_Type_IMP(Inverter *self) {
    InverterEntry *current = Inverter_IVARS(self)->current;
    return InvEntry_IVARS(current)->type;
}
Beispiel #12
0
Obj*
Inverter_Get_Value_IMP(Inverter *self) {
    InverterEntry *current = Inverter_IVARS(self)->current;
    return InvEntry_IVARS(current)->value;
}
Beispiel #13
0
String*
Inverter_Get_Field_Name_IMP(Inverter *self) {
    InverterEntry *current = Inverter_IVARS(self)->current;
    return InvEntry_IVARS(current)->field;
}
Beispiel #14
0
Doc*
Inverter_Get_Doc_IMP(Inverter *self) {
    return Inverter_IVARS(self)->doc;
}
Beispiel #15
0
float
Inverter_Get_Boost_IMP(Inverter *self) {
    return Inverter_IVARS(self)->boost;
}
Beispiel #16
0
void
Inverter_Set_Doc_IMP(Inverter *self, Doc *doc) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    Inverter_Clear(self); // Zap all cached field values and Inversions.
    ivars->doc = (Doc*)INCREF(doc);
}
Beispiel #17
0
void
Inverter_invert_doc(Inverter *self, Doc *doc) {
    InverterIVARS *const ivars = Inverter_IVARS(self);
    Hash *const fields = (Hash*)Doc_Get_Fields(doc);
    uint32_t   num_keys     = Hash_Iterate(fields);

    // Prepare for the new doc.
    Inverter_Set_Doc(self, doc);

    // Extract and invert the doc's fields.
    while (num_keys--) {
        Obj *key, *obj;
        Hash_Next(fields, &key, &obj);
        CharBuf *field = (CharBuf*)CERTIFY(key, CHARBUF);
        InverterEntry *inventry = S_fetch_entry(ivars, field);
        InverterEntryIVARS *inventry_ivars = InvEntry_IVARS(inventry);
        FieldType *type = inventry_ivars->type;

        // Get the field value.
        switch (FType_Primitive_ID(type) & FType_PRIMITIVE_ID_MASK) {
            case FType_TEXT: {
                    CharBuf *char_buf
                        = (CharBuf*)CERTIFY(obj, CHARBUF);
                    ViewCharBuf *value
                        = (ViewCharBuf*)inventry_ivars->value;
                    ViewCB_Assign(value, char_buf);
                    break;
                }
            case FType_BLOB: {
                    ByteBuf *byte_buf
                        = (ByteBuf*)CERTIFY(obj, BYTEBUF);
                    ViewByteBuf *value
                        = (ViewByteBuf*)inventry_ivars->value;
                    ViewBB_Assign(value, byte_buf);
                    break;
                }
            case FType_INT32: {
                    int32_t int_val = (int32_t)Obj_To_I64(obj);
                    Integer32* value = (Integer32*)inventry_ivars->value;
                    Int32_Set_Value(value, int_val);
                    break;
                }
            case FType_INT64: {
                    int64_t int_val = Obj_To_I64(obj);
                    Integer64* value = (Integer64*)inventry_ivars->value;
                    Int64_Set_Value(value, int_val);
                    break;
                }
            case FType_FLOAT32: {
                    float float_val = (float)Obj_To_F64(obj);
                    Float32* value = (Float32*)inventry_ivars->value;
                    Float32_Set_Value(value, float_val);
                    break;
                }
            case FType_FLOAT64: {
                    double float_val = Obj_To_F64(obj);
                    Float64* value = (Float64*)inventry_ivars->value;
                    Float64_Set_Value(value, float_val);
                    break;
                }
            default:
                THROW(ERR, "Unrecognized type: %o", type);
        }

        Inverter_Add_Field(self, inventry);
    }
}
Beispiel #18
0
Inversion*
Inverter_Get_Inversion_IMP(Inverter *self) {
    InverterEntry *current = Inverter_IVARS(self)->current;
    return InvEntry_IVARS(current)->inversion;
}