Java 类org.apache.lucene.search.highlight.SimpleHTMLEncoder 实例源码

项目:elasticsearch_my    文件:CustomPassageFormatterTests.java   
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."));
}
项目:elasticsearch_my    文件:CustomPassageFormatterTests.java   
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."));
}
项目:search    文件:SimpleFragmentsBuilderTest.java   
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() ) );
}
项目:NYBC    文件:SimpleFragmentsBuilderTest.java   
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() ) );
}
项目:Maskana-Gestor-de-Conocimiento    文件:SimpleFragmentsBuilderTest.java   
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() ) );
}
项目:search    文件:HtmlEncoder.java   
@Override
public Encoder getEncoder(String fieldName, SolrParams params) {
  return new SimpleHTMLEncoder();
}
项目:NYBC    文件:HtmlEncoder.java   
@Override
public Encoder getEncoder(String fieldName, SolrParams params) {
  return new SimpleHTMLEncoder();
}
项目:search-core    文件:HtmlEncoder.java   
@Override
public Encoder getEncoder(String fieldName, SolrParams params) {
  return new SimpleHTMLEncoder();
}
项目:read-open-source-code    文件:HtmlEncoder.java   
@Override
public Encoder getEncoder(String fieldName, SolrParams params) {
  return new SimpleHTMLEncoder();
}
项目:read-open-source-code    文件:HtmlEncoder.java   
@Override
public Encoder getEncoder(String fieldName, SolrParams params) {
  return new SimpleHTMLEncoder();
}