void HLWriter_Add_Inverted_Doc_IMP(HighlightWriter *self, Inverter *inverter, int32_t doc_id) { HighlightWriterIVARS *const ivars = HLWriter_IVARS(self); OutStream *dat_out = S_lazy_init(self); OutStream *ix_out = ivars->ix_out; int64_t filepos = OutStream_Tell(dat_out); uint32_t num_highlightable = 0; int32_t expected = (int32_t)(OutStream_Tell(ix_out) / 8); // Verify doc id. if (doc_id != expected) { THROW(ERR, "Expected doc id %i32 but got %i32", expected, doc_id); } // Write index data. OutStream_Write_I64(ix_out, filepos); // Count, then write number of highlightable fields. Inverter_Iterate(inverter); while (Inverter_Next(inverter)) { FieldType *type = Inverter_Get_Type(inverter); if (FType_Is_A(type, FULLTEXTTYPE) && FullTextType_Highlightable((FullTextType*)type) ) { num_highlightable++; } } OutStream_Write_C32(dat_out, num_highlightable); Inverter_Iterate(inverter); while (Inverter_Next(inverter)) { FieldType *type = Inverter_Get_Type(inverter); if (FType_Is_A(type, FULLTEXTTYPE) && FullTextType_Highlightable((FullTextType*)type) ) { String *field = Inverter_Get_Field_Name(inverter); Inversion *inversion = Inverter_Get_Inversion(inverter); ByteBuf *tv_buf = HLWriter_TV_Buf(self, inversion); Freezer_serialize_string(field, dat_out); Freezer_serialize_bytebuf(tv_buf, dat_out); DECREF(tv_buf); } } }
void HLWriter_add_inverted_doc(HighlightWriter *self, Inverter *inverter, i32_t doc_id) { OutStream *dat_out = S_lazy_init(self); OutStream *ix_out = self->ix_out; i64_t filepos = OutStream_Tell(dat_out); u32_t num_highlightable = 0; i32_t expected = (i32_t)(OutStream_Tell(ix_out) / 8); /* Verify doc id. */ if (doc_id != expected) THROW("Expected doc id %i32 but got %i32", expected, doc_id); /* Write index data. */ OutStream_Write_U64(ix_out, filepos); /* Count, then write number of highlightable fields. */ Inverter_Iter_Init(inverter); while (Inverter_Next(inverter)) { FieldType *type = Inverter_Get_Type(inverter); if ( OBJ_IS_A(type, FULLTEXTTYPE) && FullTextType_Highlightable(type) ) { num_highlightable++; } } OutStream_Write_C32(dat_out, num_highlightable); Inverter_Iter_Init(inverter); while (Inverter_Next(inverter)) { FieldType *type = Inverter_Get_Type(inverter); if ( OBJ_IS_A(type, FULLTEXTTYPE) && FullTextType_Highlightable(type) ) { CharBuf *field = Inverter_Get_Field_Name(inverter); Inversion *inversion = Inverter_Get_Inversion(inverter); ByteBuf *tv_buf = HLWriter_TV_Buf(self, inversion); CB_Serialize(field, dat_out); BB_Serialize(tv_buf, dat_out); DECREF(tv_buf); } } }