Hash* FullTextType_dump(FullTextType *self) { Hash *dump = FullTextType_Dump_For_Schema(self); Hash_Store_Str(dump, "_class", 6, (Obj*)CB_Clone(FullTextType_Get_Class_Name(self))); Hash_Store_Str(dump, "analyzer", 8, (Obj*)Analyzer_Dump(self->analyzer)); DECREF(Hash_Delete_Str(dump, "type", 4)); return dump; }
Hash* FullTextType_Dump_IMP(FullTextType *self) { FullTextTypeIVARS *const ivars = FullTextType_IVARS(self); Hash *dump = FullTextType_Dump_For_Schema(self); Hash_Store_Utf8(dump, "_class", 6, (Obj*)Str_Clone(FullTextType_get_class_name(self))); Hash_Store_Utf8(dump, "analyzer", 8, (Obj*)Analyzer_Dump(ivars->analyzer)); DECREF(Hash_Delete_Utf8(dump, "type", 4)); return dump; }
static void test_Dump_Load_and_Equals(TestBatchRunner *runner) { StandardTokenizer *tokenizer = StandardTokenizer_new(); Normalizer *normalizer = Normalizer_new(NULL, true, false); FullTextType *type = FullTextType_new((Analyzer*)tokenizer); FullTextType *other = FullTextType_new((Analyzer*)normalizer); FullTextType *boost_differs = FullTextType_new((Analyzer*)tokenizer); FullTextType *not_indexed = FullTextType_new((Analyzer*)tokenizer); FullTextType *not_stored = FullTextType_new((Analyzer*)tokenizer); FullTextType *highlightable = FullTextType_new((Analyzer*)tokenizer); Obj *dump = (Obj*)FullTextType_Dump(type); Obj *clone = Freezer_load(dump); Obj *another_dump = (Obj*)FullTextType_Dump_For_Schema(type); FullTextType_Set_Boost(boost_differs, 1.5); FullTextType_Set_Indexed(not_indexed, false); FullTextType_Set_Stored(not_stored, false); FullTextType_Set_Highlightable(highlightable, true); // (This step is normally performed by Schema_Load() internally.) Hash_Store_Utf8((Hash*)another_dump, "analyzer", 8, INCREF(tokenizer)); FullTextType *another_clone = FullTextType_Load(type, another_dump); TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)boost_differs), "Equals() false with different boost"); TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)other), "Equals() false with different Analyzer"); TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)not_indexed), "Equals() false with indexed => false"); TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)not_stored), "Equals() false with stored => false"); TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)highlightable), "Equals() false with highlightable => true"); TEST_TRUE(runner, FullTextType_Equals(type, (Obj*)clone), "Dump => Load round trip"); TEST_TRUE(runner, FullTextType_Equals(type, (Obj*)another_clone), "Dump_For_Schema => Load round trip"); DECREF(another_clone); DECREF(dump); DECREF(clone); DECREF(another_dump); DECREF(highlightable); DECREF(not_stored); DECREF(not_indexed); DECREF(boost_differs); DECREF(other); DECREF(type); DECREF(normalizer); DECREF(tokenizer); }
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; }