LuceneCondition extends Condition { public Set<String> postProcessingFields() { Set<String> fields = new LinkedHashSet<>(); if (!StringUtils.isBlank(defaultField)) { fields.add(defaultField); } for (String term : query.split("[ ]")) { if (term.contains(":")) { fields.add(term.split(":")[0]); } } return fields; } LuceneCondition(Float boost, String defaultField, String query); Set<String> postProcessingFields(); @Override Query doQuery(Schema schema); @Override MoreObjects.ToStringHelper toStringHelper(); static final String DEFAULT_FIELD; final String query; final String defaultField; }
@Test public void testInvolvedFields() { assertEquals("Involved fields is wrong", Sets.newHashSet("f0", "f1", "f2"), lucene("f1:3 \t AND f2:").defaultField("f0").build().postProcessingFields()); assertEquals("Involved fields is wrong with default field", Sets.newHashSet(LuceneCondition.DEFAULT_FIELD), lucene("f1 f2").build().postProcessingFields()); assertEquals("Involved fields is wrong with complex expressions", Sets.newHashSet(LuceneCondition.DEFAULT_FIELD, "date"), lucene("\"jakarta apache\"^4 date:[20020101 TO 20030101]").build().postProcessingFields()); }