use of org.elasticsearch.index.query.QueryFilterBuilder in project bw-calendar-engine by Bedework.
the class ESQueryFilter method makeFilter.
private FilterBuilder makeFilter(final PropertyInfoIndex pii, final String path, final Object val, final OperationType opType) throws CalFacadeException {
final BwIcalPropertyInfoEntry bwPie = BwIcalPropertyInfo.getPinfo(pii);
switch(opType) {
case compare:
if (bwPie.getAnalyzed()) {
if (val instanceof Collection) {
final String[] vals;
try {
final Collection valsC = (Collection) val;
vals = (String[]) (valsC).toArray(new String[valsC.size()]);
} catch (final Throwable t) {
throw new CalFacadeException(CalFacadeException.filterBadOperator, "Invalid query. Multi match only allowed on strings");
}
final MultiMatchQueryBuilder mmqb = new MultiMatchQueryBuilder(path, vals);
return new QueryFilterBuilder(mmqb);
}
return new QueryFilterBuilder(new MatchQueryBuilder(path, val));
}
if (val instanceof Collection) {
final TermsFilterBuilder tfb = FilterBuilders.termsFilter(path, (Collection) val);
tfb.execution("or");
return tfb;
}
return new TermFilterBuilder(path, val);
case timeRange:
final RangeFilterBuilder rfb = FilterBuilders.rangeFilter(path);
final TimeRange tr = (TimeRange) val;
if (tr.getEnd() == null) {
rfb.gte(tr.getStart().toString());
return rfb;
}
if (tr.getStart() == null) {
rfb.lt(tr.getEnd().toString());
return rfb;
}
rfb.from(tr.getStart().toString());
rfb.to(tr.getEnd().toString());
rfb.includeLower(true);
rfb.includeUpper(false);
return rfb;
case absence:
return FilterBuilders.missingFilter(path);
case presence:
return FilterBuilders.existsFilter(path);
case prefix:
return FilterBuilders.prefixFilter(path, (String) val);
default:
throw new CalFacadeException(CalFacadeException.filterBadOperator, opType.toString());
}
}
Aggregations