Exemplo n.º 1
0
/**
 * 为构成文档内容的字符串建立倒排列表的集合
 * @param[in] env 存储着应用程序运行环境的结构体
 * @param[in] document_id 文档编号。为0时表示把要查询的关键词作为处理对象
 * @param[in] text 输入的字符串
 * @param[in] text_len 输入的字符串的长度
 * @param[in] n N-gram中N的取值
 * @param[in,out] postings 倒排列表的数组(也可视作是指向小倒排索引的指针)。若传入的指针指向了NULL,
 *                         则表示要新建一个倒排列表的数组(小倒排索引)。若传入的指针指向了之前就已经存在的倒排列表的数组,
 *                         则表示要添加元素
 * @retval 0 成功
 * @retval -1 失败
 */
int
text_to_postings_lists(wiser_env *env,
                       const int document_id, const UTF32Char *text,
                       const unsigned int text_len,
                       const int n, inverted_index_hash **postings)
{
  /* FIXME: now same document update is broken. */
  int t_len, position = 0;
  const UTF32Char *t = text, *text_end = text + text_len;

  inverted_index_hash *buffer_postings = NULL;

  for (; (t_len = ngram_next(t, text_end, n, &t)); t++, position++) {
    /* 检索时,忽略掉由t中长度不足N-gram的最后几个字符构成的词元 */
    if (t_len >= n || document_id) {
      int retval, t_8_size;
      char t_8[n * MAX_UTF8_SIZE];

      utf32toutf8(t, t_len, t_8, &t_8_size);

      retval = token_to_postings_list(env, document_id, t_8, t_8_size,
                                      position, &buffer_postings);
      if (retval) { return retval; }
    }
  }

  if (*postings) {
    merge_inverted_index(*postings, buffer_postings);
  } else {
    *postings = buffer_postings;
  }

  return 0;
}
Exemplo n.º 2
0
size_t widetoutf8(const wchar_t* input, size_t inputSize, char* target, size_t targetSize, int32_t* errors)
{
#if UTF8_WCHAR_UTF16
	return utf16toutf8((const utf16_t*)input, inputSize, target, targetSize, errors);
#elif UTF8_WCHAR_UTF32
	return utf32toutf8((const unicode_t*)input, inputSize, target, targetSize, errors);
#else
	return SIZE_MAX;
#endif
}