QuerySuggestionSource implements SuggestionSource<SearchSuggestion> { protected List<ExpectedType> getExpectedType(String s) { final ArrayList<ExpectedType> result = new ArrayList<>(); if (s.trim().length() == 0) { result.add(ExpectedType.FIELD); return result; } String rest = getLastNotFinishedCondition(s); String trimmed = rest.trim(); System.out.printf("Checking expected type for \"%s\"%n", trimmed); if (trimmed.length() == 0 && s.matches(".*(&&|\\|\\|)\\s*") || "(".equals(s)) { result.add(ExpectedType.FIELD); } else if (rest.matches(fieldsPattern)) { result.add(ExpectedType.OPERATOR); } else if (trimmed.length() == 0 && s.matches(".+\\s+[&\\|]?")) { result.add(ExpectedType.JOIN); } else if (trimmed.length() > 0 && fields.stream().filter(x -> !x.equalsIgnoreCase(trimmed) && x.startsWith(trimmed)).findFirst().isPresent()) { result.add(ExpectedType.FIELD_TAIL); } else if (rest.matches("date\\s*" + operatorsPattern + "\\s*")) { result.add(ExpectedType.VALUE_DATE); } else if (trimmed.matches(levelPattern)) { result.add(ExpectedType.VALUE_LEVEL); } else if (rest.matches("message\\s*" + operatorsPattern + "\\s*")) { result.add(ExpectedType.VALUE_MSG); } else if (StringUtils.endsWithAny(trimmed, operators.toArray(new String[operators.size()]))) { result.add(ExpectedType.FIELD); } else if (trimmed.endsWith("(")) { result.add(ExpectedType.FIELD); } return result; } QuerySuggestionSource(List<SuggestionQuery> history); @Override List<SearchSuggestion> getSuggestions(SuggestionQuery q); String getLastValue(String s); static void main(String[] args);  }
@Test(dataProvider = "getExpectedTypeProvider", enabled = false) public void testGetExpectedType(String query, QuerySuggestionSource.ExpectedType expectedType) throws Exception { Assert.assertEquals(underTest.getExpectedType(query), Collections.singletonList(expectedType)); }