Hash* Schema_Dump_IMP(Schema *self) { SchemaIVARS *const ivars = Schema_IVARS(self); Hash *dump = Hash_new(0); Hash *type_dumps = Hash_new(Hash_Get_Size(ivars->types)); // Record class name, store dumps of unique Analyzers. Hash_Store_Utf8(dump, "_class", 6, (Obj*)Str_Clone(Schema_get_class_name(self))); Hash_Store_Utf8(dump, "analyzers", 9, Freezer_dump((Obj*)ivars->uniq_analyzers)); // Dump FieldTypes. Hash_Store_Utf8(dump, "fields", 6, (Obj*)type_dumps); HashIterator *iter = HashIter_new(ivars->types); while (HashIter_Next(iter)) { String *field = HashIter_Get_Key(iter); FieldType *type = (FieldType*)HashIter_Get_Value(iter); Class *type_class = FType_get_class(type); // Dump known types to simplified format. if (type_class == FULLTEXTTYPE) { FullTextType *fttype = (FullTextType*)type; Hash *type_dump = FullTextType_Dump_For_Schema(fttype); Analyzer *analyzer = FullTextType_Get_Analyzer(fttype); uint32_t tick = S_find_in_array(ivars->uniq_analyzers, (Obj*)analyzer); // Store the tick which references a unique analyzer. Hash_Store_Utf8(type_dump, "analyzer", 8, (Obj*)Str_newf("%u32", tick)); Hash_Store(type_dumps, field, (Obj*)type_dump); } else if (type_class == STRINGTYPE || type_class == BLOBTYPE) { Hash *type_dump = FType_Dump_For_Schema(type); Hash_Store(type_dumps, field, (Obj*)type_dump); } // Unknown FieldType type, so punt. else { Hash_Store(type_dumps, field, FType_Dump(type)); } } DECREF(iter); return dump; }
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); } }