assertEquals(expectedRes, q.toString());
}
public void testSimple() throws Exception {
String[] fields = { "b", "t" };
MultiFieldQueryParserWrapper mfqp = new MultiFieldQueryParserWrapper(
fields, new StandardAnalyzer(org.apache.lucene.util.Version.LUCENE_CURRENT));
Query q = mfqp.parse("one");
assertEquals("b:one t:one", q.toString());
q = mfqp.parse("one two");
assertEquals("(b:one t:one) (b:two t:two)", q.toString());
q = mfqp.parse("+one +two");
assertEquals("+(b:one t:one) +(b:two t:two)", q.toString());
q = mfqp.parse("+one -two -three");
assertEquals("+(b:one t:one) -(b:two t:two) -(b:three t:three)", q
.toString());
q = mfqp.parse("one^2 two");
assertEquals("((b:one t:one)^2.0) (b:two t:two)", q.toString());
q = mfqp.parse("one~ two");
assertEquals("(b:one~0.5 t:one~0.5) (b:two t:two)", q.toString());
q = mfqp.parse("one~0.8 two^2");
assertEquals("(b:one~0.8 t:one~0.8) ((b:two t:two)^2.0)", q.toString());
q = mfqp.parse("one* two*");
assertEquals("(b:one* t:one*) (b:two* t:two*)", q.toString());
q = mfqp.parse("[a TO c] two");
assertEquals("(b:[a TO c] t:[a TO c]) (b:two t:two)", q.toString());
q = mfqp.parse("w?ldcard");
assertEquals("b:w?ldcard t:w?ldcard", q.toString());
q = mfqp.parse("\"foo bar\"");
assertEquals("b:\"foo bar\" t:\"foo bar\"", q.toString());
q = mfqp.parse("\"aa bb cc\" \"dd ee\"");
assertEquals("(b:\"aa bb cc\" t:\"aa bb cc\") (b:\"dd ee\" t:\"dd ee\")", q
.toString());
q = mfqp.parse("\"foo bar\"~4");
assertEquals("b:\"foo bar\"~4 t:\"foo bar\"~4", q.toString());
// LUCENE-1213: MultiFieldQueryParserWrapper was ignoring slop when phrase
// had a field.
q = mfqp.parse("b:\"foo bar\"~4");
assertEquals("b:\"foo bar\"~4", q.toString());
// make sure that terms which have a field are not touched:
q = mfqp.parse("one f:two");
assertEquals("(b:one t:one) f:two", q.toString());
// AND mode:
mfqp.setDefaultOperator(QueryParserWrapper.AND_OPERATOR);
q = mfqp.parse("one two");
assertEquals("+(b:one t:one) +(b:two t:two)", q.toString());
q = mfqp.parse("\"aa bb cc\" \"dd ee\"");
assertEquals("+(b:\"aa bb cc\" t:\"aa bb cc\") +(b:\"dd ee\" t:\"dd ee\")",
q.toString());
}