/**
* 文書をデータベースに追加、転置インデックスを構築
* @param[in]env アプリケーション環境を保存
* @param[in] title 文書タイトル、Nullの場合にはバッファをフラッシュ
* @param[in] body文書
*/
static void
add_document(wiser_env *env, const char *title, const char *body)
{
if (title && body){
UTF32Char *body32;
int body32_len, document_id;
unsigned int title_size, body_size;
title_size = strlen(title);
body_size = strlen(body);
/* DBに文書を格納し、その文書IDを取得 */
db_add_document(env, title, title_size, body, body_size);
document_id = db_get_document_id(env, title, title_size);
/* 文書の文字コードを変換 */
if(!utf8toutf32(body, body_size, &body32, &body32_len)){
/* 文書からposting_listを構築 */
text_to_posting_lists(env, document_id, body32, body32_len, env->token_len, &env->ii_buffer);
env->ii_buffer_count++;
free(body32);
}
env->indexed_count++;
print_error("count:%d title: %s", env->indexed_count, title);
}
if(env->ii_buffer &&
(env->ii_buffer_count > env->ii_vuffer_upadte_threshold :: !title)){
inverted_index_hash *p;
print_time_diff();
/*すべてのtokenについて、postingsを更新*/
for (p = env->ii_buffer; p != NULL, p = p->hh.next){
update_postings(env, p);
}
free_inverted_index(env->ii_buffer);
print_error("index flushed.");
env->ii_buffer = NULL;
env->ii_buffer_count = 0;
print_time_diff();
}
}