org.apache.lucene.document.Document doc9;
String content9;
lenA[0]=10;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16.", content9);
lenA[0]=60;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word11 <B>hlght</B> <B>hlght</B> word12. ... word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16.", content9);
lenA[0]=100;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word5 word51 <B>hlght</B> word6. ... word11 <B>hlght</B> <B>hlght</B> word12. ... word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16.", content9);
// The tests below are algorithm dependent. Current algo starts filling with near sentences (to give some context
// from left to right, adding 1 context sentence to the right of any existing hilighted fragment.
// Then it do the same adding a context sentence to the left but starting from right to left.
lenA[0]=135;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word5 word51 <B>hlght</B> word6. word7 word8. ... word11 <B>hlght</B> <B>hlght</B> word12. ... word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16.", content9);
lenA[0]=145;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word5 word51 <B>hlght</B> word6. word7 word8. ... word11 <B>hlght</B> <B>hlght</B> word12. word13 word14. word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16.", content9);
lenA[0]=155;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word5 word51 <B>hlght</B> word6. word7 word8. ... word11 <B>hlght</B> <B>hlght</B> word12. word13 word14. word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16. word17.", content9);
lenA[0]=161;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word5 word51 <B>hlght</B> word6. word7 word8. word9 word10. word11 <B>hlght</B> <B>hlght</B> word12. word13 word14. word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16. word17.", content9);
lenA[0]=175;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word3 word4. word5 word51 <B>hlght</B> word6. word7 word8. word9 word10. word11 <B>hlght</B> <B>hlght</B> word12. word13 word14. word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16. word17.", content9);
lenA[0]=185;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word1 word2. word3 word4. word5 word51 <B>hlght</B> word6. word7 word8. word9 word10. word11 <B>hlght</B> <B>hlght</B> word12. word13 word14. word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16. word17.", content9);
lenA[0]=500;
snippetSearcher= new SnippetSearcher(new CompositeSearcher(), fieldA, lenA, FRAG_SEP, PHRASE_BOUND, false, "<B>", "</B>");
results = snippetSearcher.search(new LazyParsedQuery("hlght"), 0, 10, new NoGroup(), 1, null, null);
assertEquals("We get a bad number of groups", 1, results.groups());
assertEquals("We get a bad number of results within the group", 1, results.getGroup(0).last().size());
doc9= results.getGroup(0).last().get(0);
content9= StringUtil.nullToEmpty(doc9.get(SnippetSearcher.SNIPPET_FIELDNAME_PREFIX + "text")).trim();
assertEquals("The returned snippet is not as expected", "word1 word2. word3 word4. word5 word51 <B>hlght</B> word6. word7 word8. word9 word10. word11 <B>hlght</B> <B>hlght</B> word12. word13 word14. word15 <B>hlght</B> <B>hlght</B> <B>hlght</B> word16. word17.", content9);