• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SimpleHTMLEncoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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("&lt;b&gt;This is a really cool <em>highlighter</em>.&lt;&#x2F;b&gt;"));
    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("&lt;b&gt;This is a really cool <em>highlighter</em>.&lt;&#x2F;b&gt;"));
    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( "&lt;h1&gt; [a] &lt;&#x2F;h1&gt;",
      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( "&lt;h1&gt; [a] &lt;/h1&gt;",
      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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TaskAttemptUnsuccessfulCompletionEvent类代码示例发布时间:2022-05-22
下一篇:
Java IntHolder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap