Example #1
0
void
Schema_Spec_Field_IMP(Schema *self, String *field, FieldType *type) {
    FieldType *existing  = Schema_Fetch_Type(self, field);

    // If the field already has an association, verify pairing and return.
    if (existing) {
        if (FType_Equals(type, (Obj*)existing)) { return; }
        else { THROW(ERR, "'%o' assigned conflicting FieldType", field); }
    }

    if (FType_is_a(type, FULLTEXTTYPE)) {
        S_add_text_field(self, field, type);
    }
    else if (FType_is_a(type, STRINGTYPE)) {
        S_add_string_field(self, field, type);
    }
    else if (FType_is_a(type, BLOBTYPE)) {
        S_add_blob_field(self, field, type);
    }
    else if (FType_is_a(type, NUMERICTYPE)) {
        S_add_numeric_field(self, field, type);
    }
    else {
        THROW(ERR, "Unrecognized field type: '%o'", type);
    }
}
Example #2
0
void
Indexer_Delete_By_Term_IMP(Indexer *self, String *field, Obj *term) {
    IndexerIVARS *const ivars = Indexer_IVARS(self);
    Schema    *schema = ivars->schema;
    FieldType *type   = Schema_Fetch_Type(schema, field);

    // Raise exception if the field isn't indexed.
    if (!type || !FType_Indexed(type)) {
        THROW(ERR, "%o is not an indexed field", field);
    }

    // Analyze term if appropriate, then zap.
    if (FType_is_a(type, FULLTEXTTYPE)) {
        CERTIFY(term, STRING);
        Analyzer *analyzer = Schema_Fetch_Analyzer(schema, field);
        Vector *terms = Analyzer_Split(analyzer, (String*)term);
        Obj *analyzed_term = Vec_Fetch(terms, 0);
        if (analyzed_term) {
            DelWriter_Delete_By_Term(ivars->del_writer, field,
                                     analyzed_term);
        }
        DECREF(terms);
    }
    else {
        DelWriter_Delete_By_Term(ivars->del_writer, field, term);
    }
}