1. 高亮
HighlighterPtr highlighter;
if (indices_data_[ctx->current_index_]->high_light_ == 1){
SimpleHTMLFormatterPtr formatter = newLucene<SimpleHTMLFormatter>(indices_data_[ctx->current_index_]->pre_tag_, indices_data_[ctx->current_index_]->post_tag_);
LOG(DEBUG) << "pre_tag:" << StringUtils::toUTF8(indices_data_[ctx->current_index_]->pre_tag_);
LOG(DEBUG) << "post_tag:" << StringUtils::toUTF8(indices_data_[ctx->current_index_]->post_tag_);
QueryPtr qquery = query;
if (ctx->query_deformed_ == 1){
string err;
qquery = QueryBuilder::BuildQueryEx(analyzer, ctx->kw_r_, ctx->filters_r_, 0, indices_data_[ctx->current_index_]->min_should_,
reader_filters_[ctx->current_index_], indices_exact_fields_[ctx->current_index_], err, ctx->current_index_, ctx, 1, indices_data_[ctx->current_index_]->search_rule_);
}
if (qquery) {
QueryScorerPtr scorer = newLucene<QueryScorer>(qquery);
FragmenterPtr fragmenter = newLucene<SimpleSpanFragmenter>(scorer);
highlighter = newLucene<Highlighter>(formatter,scorer);
}
//highlight->setTextFragmenter(fragmenter);
}
if (highLight){
String value = fid->stringValue();
TokenStreamPtr tokenStream = analyzer->tokenStream(fid->name(), newLucene<StringReader>(value));
item.insert(sattrs[k].c_str(), StringUtils::toUTF8(highlighter->getBestFragment(tokenStream, value)));
/*
Collection<TextFragmentPtr> frag = highlighter->getBestTextFragments(tokenStream, value, false, 4);
Collection<String> fragTexts(Collection<String>::newInstance());
for (int32_t i = 0; i < frag.size(); ++i) {
LOG(DEBUG) << "frag:" << i;
if (frag[i]){
LOG(DEBUG) << "frag score:" << frag[i]->getScore();
LOG(DEBUG) << "frag text:" << StringUtils::toUTF8(frag[i]->toString());
}
if (frag[i] && frag[i]->getScore() > 0) {
fragTexts.add(frag[i]->toString());
LOG(DEBUG) << StringUtils::toUTF8(frag[i]->toString());
}
}
if (fragTexts.empty()) {
item.insert(sattrs[k].c_str(), StringUtils::toUTF8(value));
LOG(DEBUG) << "highlight failed";
}
else{
item.insert(sattrs[k].c_str(), StringUtils::toUTF8(fragTexts[0]));
}
*/
}
else{
item.insert(sattrs[k].c_str(), StringUtils::toUTF8(fid->stringValue()));
}