public static Object parseDecorateInstruction(String line) { if (line.length() == INSTR_DECORATE.length()) { return new ValidationError(INSTR_DECORATE + " requires a value"); } String decValue = line.substring(INSTR_DECORATE.length()).trim(); if (decValue.charAt(0) != ':') { return new ValidationError("Cannot parse line, ':' expetcted in " + line); } decValue = decValue.substring(1).trim(); if (decValue.length() == 0) { return new ValidationError(INSTR_DECORATE + " requires a value"); } return new DecorateInstruction(decValue); }
@SuppressWarnings("unchecked") public static Object parseInput(String s) { boolean requiresLeftBoundary = false; boolean requiresRightBoundary = false; s = s.trim(); if (s.length() > 0 && s.charAt(0) == BOUNDARY) { requiresLeftBoundary = true; s = s.substring(1).trim(); } if (s.length() > 0 && s.charAt(s.length() - 1) == BOUNDARY) { requiresRightBoundary = true; s = s.substring(0, s.length() - 1).trim(); } int pos = s.indexOf('*'); if (pos > -1) { if (pos < (s.length() -1)) { return new ValidationError(WILDCARD + " is only allowed at the end of the input: " + s); } else if (requiresRightBoundary) { return new ValidationError(WILDCARD + " cannot be combined with right boundary"); } } Object expr = parseTermExpression(s); return (expr instanceof ValidationError) ? expr : new Input((List<Term>) expr, requiresLeftBoundary, requiresRightBoundary); }
static Object parseTermExpression(String s) { int len = s.length(); if (len == 1) { char ch = s.charAt(0); if (ch == WILDCARD) { return new ValidationError("Missing prefix for wildcard " + WILDCARD); } Term term = new Term(new char[] {ch}, 0, 1, null); return Arrays.asList(term); } List<Term> terms = new LinkedList<>(); for (String part : s.split("\\s+")) { if (part.length() > 0) { terms.add(parseTerm(part)); } } return terms; }
public static Object parseBoostInstruction(String line, String lcLine, int lengthPredicate, BoostDirection direction, QuerqyParserFactory querqyParserFactory) { return new ValidationError("Cannot parse line: " + line); return new ValidationError("Cannot parse line, expecting boost factor and ':' after '(' in " + line); return new ValidationError("Query expected: " + line); return new ValidationError("Cannot parse line, '(' or ':' expected: " + line); int pos = boostLine.indexOf(')'); if (pos < 1 || (pos == boostLine.length() - 1)) { return new ValidationError("Cannot parse line: " + line); return new ValidationError("Query expected: " + line); return new ValidationError("Query expected: " + line); return new ValidationError("Missing raw query after " + RAWQUERY + " in line: " + line); return new ValidationError("No querqy parser factory to parse filter query. Prefix '" + RAWQUERY + "' you want to pass this line as a raw query String to your search engine. Line: " + line);
return new ValidationError("Empty input"); return new ValidationError("Missing input for instruction"); return new ValidationError("Cannot parse line: " + line); Object expr = parseTermExpression(instructionTerms); if (expr instanceof ValidationError) { return new ValidationError("Cannot parse line: " + line +" : " + ((ValidationError)expr).getMessage()); for (Term term: deleteTerms) { if (term.findFirstMatch(inputTerms) == null) { return new ValidationError("Condition doesn't contain the term to delete: " + term); return new ValidationError("Cannot parse line: " + line); return new ValidationError("Cannot parse line: " + line); return new ValidationError("Cannot parse line: " + line); return new ValidationError("Missing raw query after * in line: " + line); return new ValidationError("No querqy parser factory to parse filter query. Prefix '*' if you want to pass this line as a raw query String to your search engine. Line: " + line); } else { QuerqyParser parser = querqyParserFactory.createParser(); return new ValidationError("Cannot parse line: " + line); return new ValidationError("Cannot parse line, ':' expetcted in " + line);
@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); }