use of org.opengrok.indexer.search.QueryBuilder in project OpenGrok by OpenGrok.
the class ContextTest method testIsEmpty.
/**
* Tests for the isEmpty() method.
* @throws org.apache.lucene.queryparser.classic.ParseException parse exception
*/
@Test
public void testIsEmpty() throws ParseException {
String term = "qwerty";
// Definition search should be used
QueryBuilder qb = new QueryBuilder().setDefs(term);
Context c = new Context(qb.build(), qb);
assertFalse(c.isEmpty());
// Symbol search should be used
qb = new QueryBuilder().setRefs(term);
c = new Context(qb.build(), qb);
assertFalse(c.isEmpty());
// Full search should be used
qb = new QueryBuilder().setFreetext(term);
c = new Context(qb.build(), qb);
assertFalse(c.isEmpty());
// History search should not be used
qb = new QueryBuilder().setHist(term);
c = new Context(qb.build(), qb);
assertTrue(c.isEmpty());
// Path search should not be used
qb = new QueryBuilder().setPath(term);
c = new Context(qb.build(), qb);
assertTrue(c.isEmpty());
// Combined search should be fine
qb = new QueryBuilder().setHist(term).setFreetext(term);
c = new Context(qb.build(), qb);
assertFalse(c.isEmpty());
}
use of org.opengrok.indexer.search.QueryBuilder in project OpenGrok by OpenGrok.
the class ContextTest method testLongTruncatedLine.
/**
* Test that a line with more than 100 characters after the first match is
* truncated, and that … is appended to show that the line is
* truncated. Bug 383.
* @throws org.apache.lucene.queryparser.classic.ParseException parse exception
*/
@Test
public void testLongTruncatedLine() throws ParseException {
StringBuilder sb = new StringBuilder();
sb.append("search_for_me");
while (sb.length() <= 100) {
sb.append(" more words");
}
sb.append("should not be found");
Reader in = new StringReader(sb.toString());
StringWriter out = new StringWriter();
QueryBuilder qb = new QueryBuilder().setFreetext("search_for_me");
Context c = new Context(qb.build(), qb);
boolean match = c.getContext(in, out, "", "", "", null, true, qb.isDefSearch(), null);
assertTrue(match, "No match found");
String s = out.toString();
assertTrue(s.contains("<b>search_for_me</b>"), "Match not listed");
assertFalse(s.contains("should not be found"), "Line not truncated");
assertTrue(s.contains("…"), "Ellipsis not found");
}
Aggregations