private static int multiToken = 0;
public void testMultiAnalyzer() throws QueryNodeException {
StandardQueryParser qp = new StandardQueryParser();
qp.setAnalyzer(new MultiAnalyzer());
// trivial, no multiple tokens:
assertEquals("foo", qp.parse("foo", "").toString());
assertEquals("foo", qp.parse("\"foo\"", "").toString());
assertEquals("foo foobar", qp.parse("foo foobar", "").toString());
assertEquals("\"foo foobar\"", qp.parse("\"foo foobar\"", "").toString());
assertEquals("\"foo foobar blah\"", qp.parse("\"foo foobar blah\"", "")
.toString());
// two tokens at the same position:
assertEquals("(multi multi2) foo", qp.parse("multi foo", "").toString());
assertEquals("foo (multi multi2)", qp.parse("foo multi", "").toString());
assertEquals("(multi multi2) (multi multi2)", qp.parse("multi multi", "")
.toString());
assertEquals("+(foo (multi multi2)) +(bar (multi multi2))", qp.parse(
"+(foo multi) +(bar multi)", "").toString());
assertEquals("+(foo (multi multi2)) field:\"bar (multi multi2)\"", qp
.parse("+(foo multi) field:\"bar multi\"", "").toString());
// phrases:
assertEquals("\"(multi multi2) foo\"", qp.parse("\"multi foo\"", "")
.toString());
assertEquals("\"foo (multi multi2)\"", qp.parse("\"foo multi\"", "")
.toString());
assertEquals("\"foo (multi multi2) foobar (multi multi2)\"", qp.parse(
"\"foo multi foobar multi\"", "").toString());
// fields:
assertEquals("(field:multi field:multi2) field:foo", qp.parse(
"field:multi field:foo", "").toString());
assertEquals("field:\"(multi multi2) foo\"", qp.parse(
"field:\"multi foo\"", "").toString());
// three tokens at one position:
assertEquals("triplemulti multi3 multi2", qp.parse("triplemulti", "")
.toString());
assertEquals("foo (triplemulti multi3 multi2) foobar", qp.parse(
"foo triplemulti foobar", "").toString());
// phrase with non-default slop:
assertEquals("\"(multi multi2) foo\"~10", qp.parse("\"multi foo\"~10", "")
.toString());
// phrase with non-default boost:
assertEquals("\"(multi multi2) foo\"^2.0", qp.parse("\"multi foo\"^2", "")
.toString());
// phrase after changing default slop
qp.setDefaultPhraseSlop(99);
assertEquals("\"(multi multi2) foo\"~99 bar", qp.parse("\"multi foo\" bar",
"").toString());
assertEquals("\"(multi multi2) foo\"~99 \"foo bar\"~2", qp.parse(
"\"multi foo\" \"foo bar\"~2", "").toString());
qp.setDefaultPhraseSlop(0);
// non-default operator:
qp.setDefaultOperator(Operator.AND);
assertEquals("+(multi multi2) +foo", qp.parse("multi foo", "").toString());
}