本文整理汇总了Java中org.elasticsearch.index.query.FilterBuilders.rangeFilter方法的典型用法代码示例。如果您正苦于以下问题:Java FilterBuilders.rangeFilter方法的具体用法?Java FilterBuilders.rangeFilter怎么用?Java FilterBuilders.rangeFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.index.query.FilterBuilders
的用法示例。
在下文中一共展示了FilterBuilders.rangeFilter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rangeFilter
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
public FilterBuilder rangeFilter(String name) {
FilterBuilder filter = null;
if(max.isPresent() && max.get() == 0) {
filter = FilterBuilders.notFilter(FilterBuilders.existsFilter(name));
} else {
RangeFilterBuilder rfilter = FilterBuilders.rangeFilter(name);
min.ifPresent(m -> rfilter.from(m));
max.ifPresent(m -> rfilter.to(m));
filter = rfilter;
}
return filter;
}
示例2: buildSingleRangeFilter
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
private FilterBuilder buildSingleRangeFilter(String key, String value) {
String[] values = value.split(" - ");
if (value.length() == 0) {
return null;
}
RangeFilterBuilder filterBuilder = FilterBuilders.rangeFilter(key);
if (value.length() == 2) {
filterBuilder.from(Double.valueOf(values[0]).doubleValue()).to(Double.valueOf(values[1]));
} else if (value.startsWith(values[0])) {
filterBuilder.gte(Double.valueOf(values[0]).doubleValue());
} else {
filterBuilder.lt(Double.valueOf(values[0]).doubleValue());
}
return filterBuilder;
}
示例3: buildQuery
import org.elasticsearch.index.query.FilterBuilders; //导入方法依赖的package包/类
@Override
public QueryBuilder buildQuery(List<FilterBuilder> builders, Map<String, FilterValue> filterParams) {
List<FilterBuilder> filterBuilders = new ArrayList<>();
if(filterParams != null) {
for (String key : filterParams.keySet()) {
FilterValue filterValue = filterParams.get(key);
FilterType filterType = filterValue.getFilterType();
Set<Object> value = filterValue.getValues();
if (filterType == FilterType.RANGE) {
RangeFilterBuilder rangeFilterBuilder = FilterBuilders.rangeFilter(key);
Object[] values = value.toArray();
if (value.size() > 1) {
rangeFilterBuilder.from(Double.parseDouble((String) values[0]));
rangeFilterBuilder.to(Double.parseDouble((String) values[1]));
} else if (value.size() > 0) {
rangeFilterBuilder.from(Double.parseDouble((String) values[0]));
} else {
rangeFilterBuilder.from(0);
}
filterBuilders.add(rangeFilterBuilder);
} else {
if (value.size() > 1) {
filterBuilders.add(FilterBuilders.termsFilter(key, value.toArray()).execution("or"));
} else if (value.size() > 0) {
filterBuilders.add(FilterBuilders.termsFilter(key, value.iterator().next()));
}
}
}
}
if (builders != null && !builders.isEmpty())
filterBuilders.addAll(builders);
if(filterBuilders.size() > 1){
FilterBuilder andFilterBuilder = FilterBuilders
.andFilter(filterBuilders.toArray(new FilterBuilder[filterBuilders.size()]));
return QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), andFilterBuilder);
} else {
return QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filterBuilders.get(0));
}
}
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:50,代码来源:DefaultElasticsearchHelper.java