public void testHighlightingWithDefaultField() throws Exception {
String s1 = "I call our world Flatland, not because we call it so,";
QueryParser parser = new QueryParser(FIELD_NAME, new StandardAnalyzer(Version.LUCENE_CURRENT));
// Verify that a query against the default field results in text being
// highlighted
// regardless of the field name.
Query q = parser.parse("\"world Flatland\"~3");
String expected = "I call our <B>world</B> <B>Flatland</B>, not because we call it so,";
String observed = highlightField(q, "SOME_FIELD_NAME", s1);
System.out.println("Expected: \"" + expected + "\n" + "Observed: \"" + observed);
assertEquals("Query in the default field results in text for *ANY* field being highlighted",
expected, observed);
// Verify that a query against a named field does not result in any
// highlighting
// when the query field name differs from the name of the field being
// highlighted,
// which in this example happens to be the default field name.
q = parser.parse("text:\"world Flatland\"~3");
expected = s1;
observed = highlightField(q, FIELD_NAME, s1);
System.out.println("Expected: \"" + expected + "\n" + "Observed: \"" + observed);
assertEquals(
"Query in a named field does not result in highlighting when that field isn't in the query",