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.")); }
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.")); }
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() ) ); }
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() ) ); }
@Override public Encoder getEncoder(String fieldName, SolrParams params) { return new SimpleHTMLEncoder(); }