/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Test QueryParser's ability to deal with Analyzers that return more
* than one token per position or that return tokens with a position
* increment > 1.
*
*/
// trivial, no multiple tokens:
// two tokens at the same position:
assertEquals("+(foo (multi multi2)) +(bar (multi multi2))",
assertEquals("+(foo (multi multi2)) field:\"bar (multi multi2)\"",
// phrases:
assertEquals("\"foo (multi multi2) foobar (multi multi2)\"",
// fields:
// three tokens at one position:
assertEquals("foo (triplemulti multi3 multi2) foobar",
// phrase with non-default slop:
// phrase with non-default boost:
// phrase after changing default slop
assertEquals("\"(multi multi2) foo\"~99 bar",
assertEquals("\"(multi multi2) foo\"~99 \"foo bar\"~2",
// non-default operator:
}
// direct call to (super's) getFieldQuery to demonstrate differnce
// between phrase and multiphrase with modified default slop
assertEquals("\"foo bar\"~99",
assertEquals("\"(multi multi2) bar\"~99",
// ask sublcass to parse phrase with modified default slop
assertEquals("\"(multi multi2) foo\"~99 bar",
}
}
/**
* Expands "multi" to "multi" and "multi2", both at the same position,
* and expands "triplemulti" to "triplemulti", "multi3", and "multi2".
*/
public MultiAnalyzer() {
}
return result;
}
}
private int prevStartOffset;
private int prevEndOffset;
super(in);
}
if (multiToken > 0) {
multiToken--;
return true;
} else {
if (!next) {
return false;
}
multiToken = 2;
return true;
multiToken = 1;
return true;
} else {
return true;
}
}
}
super.reset();
this.prevStartOffset = 0;
this.prevEndOffset = 0;
}
}
/**
* Analyzes "the quick brown" as: quick(incr=2) brown(incr=1).
* Does not work correctly for input other than "the quick brown ...".
*/
public PosIncrementAnalyzer() {
}
return result;
}
}
super(in);
}
while(input.incrementToken()) {
// stopword, do nothing
return true;
} else {
return true;
}
}
return false;
}
}
/** a very simple subclass of QueryParser */
super(TEST_VERSION_CURRENT, f, a);
}
/** expose super's version */
throws ParseException {
return super.getFieldQuery(f,t,quoted);
}
/** wrap super's version */
throws ParseException {
}
}
/**
* A very simple wrapper to prevent instanceof checks but uses
* the toString of the query it wraps.
*/
private Query q;
super();
this.q = q;
}
return q.toString(f);
}
}
}