@Override public QueryRewriter createRewriter(ExpandedQuery input, Map<String, ?> context) { return new CommonRulesRewriter(rules); }
public void nextLine(String line) throws RuleParseException { line = stripLine(line); if (line.length() > 0) { Object lineObject = LineParser.parse(line, input, querqyParserFactory); if (lineObject instanceof Input) { putRule(); input = (Input) lineObject; instructions = new Instructions(); } else if (lineObject instanceof ValidationError) { throw new RuleParseException(lineNumber, ((ValidationError) lineObject).getMessage()); } else { instructions.add((Instruction) lineObject); } } }
RulesCollection createRulesFromResource(String resourceName, boolean ignoreCase) throws IOException, RuleParseException { SimpleCommonRulesParser parser = createParserFromResource(resourceName, ignoreCase); return parser.parse(); }
@Test public void testThatBoostInstructionWithSingleLetterTermIsAccepted() throws Exception { String line = "UP: x"; String lcLine = line.toLowerCase(); final Object instruction = LineParser .parseBoostInstruction(line, lcLine, 2, BoostDirection.UP, new WhiteSpaceQuerqyParserFactory()); assertTrue(instruction instanceof BoostInstruction); }
@SuppressWarnings("unchecked") @Test public void testParseTermExpressionMultipleTerms() { assertThat((List<Term>) LineParser.parseTermExpression("abc def"), contains(term("abc"), term("def"))); }
@SuppressWarnings("unchecked") @Test public void testParseTermExpressionMixed() { assertThat((List<Term>) LineParser.parseTermExpression("abc* def ghij* klmn"), contains(prefix("abc"), term("def"), prefix("ghij"), term("klmn"))); }
@Test public void testThatWildcardCannotBeFollowedByRightBoundary() throws Exception { Object parseResult = LineParser.parseInput("a" + LineParser.WILDCARD + LineParser.BOUNDARY); assertEquals("Wildcard should not be allowed before right boundary", new ValidationError(LineParser.WILDCARD + " cannot be combined with right boundary"), parseResult); }
@SuppressWarnings("unchecked") @Test public void testParseTermExpressionMultiplePrefixes() { assertThat((List<Term>) LineParser.parseTermExpression("abc* def*"), contains(prefix("abc"), prefix("def"))); }
@Test public void testStripLine() { SimpleCommonRulesParser parser = createParserWithEmptyReader(); assertEquals("", parser.stripLine("")); assertEquals("", parser.stripLine(" ")); assertEquals("", parser.stripLine("#dss")); assertEquals("", parser.stripLine(" #sdsd")); assertEquals("", parser.stripLine("\t #sdsd")); }
@Test public void testError01() throws Exception { try { createRulesFromResource("rules-with-errors01.txt", false); fail(); } catch (RuleParseException e) { assertEquals("Line 5: Condition doesn't contain the term to delete: " + "Term [fieldNames=null, value=c]", e.getMessage()); } }
TermMatcher term(String value, String...fieldNames) { return new TermMatcher(Term.class, value, fieldNames); }
@Test public void testThatBoostInstructionWithSingleLetterTermAndBoostFactorIsAccepted() throws Exception { String line = "UP(5): x"; String lcLine = line.toLowerCase(); final Object instruction = LineParser .parseBoostInstruction(line, lcLine, 2, BoostDirection.UP, new WhiteSpaceQuerqyParserFactory()); assertTrue(instruction instanceof BoostInstruction); }
@SuppressWarnings("unchecked") @Test public void testParseTermExpressionSingleTerm() { assertThat((List<Term>) LineParser.parseTermExpression("abc"), contains(term("abc"))); }
@Override public QueryRewriter createRewriter(final ExpandedQuery input, final Map<String, ?> context) { return new CommonRulesRewriter(rules); }
TermMatcher prefix(String value, String...fieldNames) { return new TermMatcher(PrefixTerm.class, value, fieldNames); }
@SuppressWarnings("unchecked") @Test public void testParseTermExpressionSingleLetter() { assertThat((List<Term>) LineParser.parseTermExpression("a"), contains(term("a"))); }