static void test_Dump_Load_and_Equals(TestBatch *batch) { PolyAnalyzer *analyzer = PolyAnalyzer_new((CharBuf*)&EN, NULL); PolyAnalyzer *other = PolyAnalyzer_new((CharBuf*)&ES, NULL); Obj *dump = (Obj*)PolyAnalyzer_Dump(analyzer); Obj *other_dump = (Obj*)PolyAnalyzer_Dump(other); PolyAnalyzer *clone = (PolyAnalyzer*)PolyAnalyzer_Load(other, dump); PolyAnalyzer *other_clone = (PolyAnalyzer*)PolyAnalyzer_Load(other, other_dump); ASSERT_FALSE(batch, PolyAnalyzer_Equals(analyzer, (Obj*)other), "Equals() false with different language"); ASSERT_TRUE(batch, PolyAnalyzer_Dump_Equals(other, (Obj*)other_dump), "Dump_Equals()"); ASSERT_TRUE(batch, PolyAnalyzer_Dump_Equals(analyzer, (Obj*)dump), "Dump_Equals()"); ASSERT_FALSE(batch, PolyAnalyzer_Dump_Equals(analyzer, (Obj*)other_dump), "Dump_Equals() false with different language"); ASSERT_FALSE(batch, PolyAnalyzer_Dump_Equals(other, (Obj*)dump), "Dump_Equals() false with different language"); ASSERT_TRUE(batch, PolyAnalyzer_Equals(analyzer, (Obj*)clone), "Dump => Load round trip"); ASSERT_TRUE(batch, PolyAnalyzer_Equals(other, (Obj*)other_clone), "Dump => Load round trip"); DECREF(analyzer); DECREF(dump); DECREF(clone); DECREF(other); DECREF(other_dump); DECREF(other_clone); }
static Folder* build_index() { // Plain type. String *pattern = Str_newf("\\S+"); RegexTokenizer *tokenizer = RegexTokenizer_new(pattern); FullTextType *plain = FullTextType_new((Analyzer*)tokenizer); // Fancy type. String *word_pattern = Str_newf("\\w+"); RegexTokenizer *word_tokenizer = RegexTokenizer_new(word_pattern); Hash *stop_list = Hash_new(0); Hash_Store_Utf8(stop_list, "x", 1, (Obj*)CFISH_TRUE); SnowballStopFilter *stop_filter = SnowStop_new(NULL, stop_list); Vector *analyzers = Vec_new(0); Vec_Push(analyzers, (Obj*)word_tokenizer); Vec_Push(analyzers, (Obj*)stop_filter); PolyAnalyzer *fancy_analyzer = PolyAnalyzer_new(NULL, analyzers); FullTextType *fancy = FullTextType_new((Analyzer*)fancy_analyzer); // Schema. Schema *schema = Schema_new(); String *plain_str = Str_newf("plain"); String *fancy_str = Str_newf("fancy"); Schema_Spec_Field(schema, plain_str, (FieldType*)plain); Schema_Spec_Field(schema, fancy_str, (FieldType*)fancy); // Indexer. RAMFolder *folder = RAMFolder_new(NULL); Indexer *indexer = Indexer_new(schema, (Obj*)folder, NULL, 0); // Index documents. Vector *doc_set = TestUtils_doc_set(); for (uint32_t i = 0; i < Vec_Get_Size(doc_set); ++i) { String *content_string = (String*)Vec_Fetch(doc_set, i); Doc *doc = Doc_new(NULL, 0); Doc_Store(doc, plain_str, (Obj*)content_string); Doc_Store(doc, fancy_str, (Obj*)content_string); Indexer_Add_Doc(indexer, doc, 1.0); DECREF(doc); } Indexer_Commit(indexer); // Clean up. DECREF(doc_set); DECREF(indexer); DECREF(fancy_str); DECREF(plain_str); DECREF(schema); DECREF(fancy); DECREF(fancy_analyzer); DECREF(analyzers); DECREF(stop_list); DECREF(word_pattern); DECREF(plain); DECREF(tokenizer); DECREF(pattern); return (Folder*)folder; }