本文整理汇总了Java中org.apache.lucene.search.highlight.SimpleHTMLEncoder类的典型用法代码示例。如果您正苦于以下问题:Java SimpleHTMLEncoder类的具体用法?Java SimpleHTMLEncoder怎么用?Java SimpleHTMLEncoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleHTMLEncoder类属于org.apache.lucene.search.highlight包,在下文中一共展示了SimpleHTMLEncoder类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testHtmlEncodeFormat
import org.apache.lucene.search.highlight.SimpleHTMLEncoder; //导入依赖的package包/类
public void testHtmlEncodeFormat() {
String content = "<b>This is a really cool highlighter.</b> Postings highlighter gives nice snippets back.";
CustomPassageFormatter passageFormatter = new CustomPassageFormatter("<em>", "</em>", new SimpleHTMLEncoder());
Passage[] passages = new Passage[2];
String match = "highlighter";
BytesRef matchBytesRef = new BytesRef(match);
Passage passage1 = new Passage();
int start = content.indexOf(match);
int end = start + match.length();
passage1.startOffset = 0;
passage1.endOffset = end + 6; //lets include the whitespace at the end to make sure we trim it
passage1.addMatch(start, end, matchBytesRef);
passages[0] = passage1;
Passage passage2 = new Passage();
start = content.lastIndexOf(match);
end = start + match.length();
passage2.startOffset = passage1.endOffset;
passage2.endOffset = content.length();
passage2.addMatch(start, end, matchBytesRef);
passages[1] = passage2;
Snippet[] fragments = passageFormatter.format(passages, content);
assertThat(fragments, notNullValue());
assertThat(fragments.length, equalTo(2));
assertThat(fragments[0].getText(), equalTo("<b>This is a really cool <em>highlighter</em>.</b>"));
assertThat(fragments[1].getText(), equalTo("Postings <em>highlighter</em> gives nice snippets back."));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:CustomPassageFormatterTests.java
示例2: testHtmlEncodeFormat
import org.apache.lucene.search.highlight.SimpleHTMLEncoder; //导入依赖的package包/类
public void testHtmlEncodeFormat() {
String content = "<b>This is a really cool highlighter.</b> Unified highlighter gives nice snippets back.";
CustomPassageFormatter passageFormatter = new CustomPassageFormatter("<em>", "</em>", new SimpleHTMLEncoder());
Passage[] passages = new Passage[2];
String match = "highlighter";
BytesRef matchBytesRef = new BytesRef(match);
Passage passage1 = new Passage();
int start = content.indexOf(match);
int end = start + match.length();
passage1.setStartOffset(0);
passage1.setEndOffset(end + 6); //lets include the whitespace at the end to make sure we trim it
passage1.addMatch(start, end, matchBytesRef);
passages[0] = passage1;
Passage passage2 = new Passage();
start = content.lastIndexOf(match);
end = start + match.length();
passage2.setStartOffset(passage1.getEndOffset());
passage2.setEndOffset(content.length());
passage2.addMatch(start, end, matchBytesRef);
passages[1] = passage2;
Snippet[] fragments = passageFormatter.format(passages, content);
assertThat(fragments, notNullValue());
assertThat(fragments.length, equalTo(2));
assertThat(fragments[0].getText(), equalTo("<b>This is a really cool <em>highlighter</em>.</b>"));
assertThat(fragments[1].getText(), equalTo("Unified <em>highlighter</em> gives nice snippets back."));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:32,代码来源:CustomPassageFormatterTests.java
示例3: testTagsAndEncoder
import org.apache.lucene.search.highlight.SimpleHTMLEncoder; //导入依赖的package包/类
public void testTagsAndEncoder() throws Exception {
FieldFragList ffl = ffl(new TermQuery(new Term(F, "a")), "<h1> a </h1>" );
SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
String[] preTags = { "[" };
String[] postTags = { "]" };
assertEquals( "<h1> [a] </h1>",
sfb.createFragment( reader, 0, F, ffl, preTags, postTags, new SimpleHTMLEncoder() ) );
}
开发者ID:europeana,项目名称:search,代码行数:9,代码来源:SimpleFragmentsBuilderTest.java
示例4: testTagsAndEncoder
import org.apache.lucene.search.highlight.SimpleHTMLEncoder; //导入依赖的package包/类
public void testTagsAndEncoder() throws Exception {
FieldFragList ffl = ffl(new TermQuery(new Term(F, "a")), "<h1> a </h1>" );
SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
String[] preTags = { "[" };
String[] postTags = { "]" };
assertEquals( "<h1> [a] </h1>",
sfb.createFragment( reader, 0, F, ffl, preTags, postTags, new SimpleHTMLEncoder() ) );
}
开发者ID:pkarmstr,项目名称:NYBC,代码行数:9,代码来源:SimpleFragmentsBuilderTest.java
示例5: getEncoder
import org.apache.lucene.search.highlight.SimpleHTMLEncoder; //导入依赖的package包/类
@Override
public Encoder getEncoder(String fieldName, SolrParams params) {
return new SimpleHTMLEncoder();
}
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:HtmlEncoder.java
注:本文中的org.apache.lucene.search.highlight.SimpleHTMLEncoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论