use of org.elasticsearch.index.query.TermsFilterBuilder in project bw-calendar-engine by Bedework.
the class TermOrTerms method makeFb.
FilterBuilder makeFb() {
final FilterBuilder fb;
if (!isTerms) {
final TermFilterBuilder tfb = FilterBuilders.termFilter(fldName, value);
if (filterName != null) {
tfb.filterName(filterName);
}
fb = tfb;
} else {
final List vals = (List) value;
FilterBuilder newFb = null;
if (anding) {
for (final Object o : vals) {
if (o instanceof MatchNone) {
// and false is always false
newFb = (FilterBuilder) o;
break;
}
}
} else {
for (final Object o : vals) {
if (o instanceof MatchAllFilterBuilder) {
// or true is always true
newFb = (FilterBuilder) o;
break;
}
}
}
if (newFb != null) {
fb = newFb;
} else {
final TermsFilterBuilder tfb = FilterBuilders.termsFilter(fldName, (Iterable<?>) value).execution(exec);
if (filterName != null) {
tfb.filterName(filterName);
}
fb = tfb;
}
}
if (!not) {
return fb;
}
if (fb instanceof MatchAllFilterBuilder) {
return new MatchNone();
}
if (fb instanceof MatchNone) {
return new MatchAllFilterBuilder();
}
return new NotFilterBuilder(fb);
}
use of org.elasticsearch.index.query.TermsFilterBuilder 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