Java 类org.elasticsearch.index.query.RangeFilterBuilder 实例源码

项目:blackmarket    文件:RangeOptional.java   
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;
}
项目:scaleset-search    文件:RangeFilterConverter.java   
@Override
public FilterBuilder convert(Filter filter) {

    boolean cache = filter.getBoolean("cache", false);
    String field = filter.getString("field");
    if (field == null) {
        field = filter.getName();
    }

    RangeFilterBuilder result = rangeFilter(field).cache(cache);
    String gte = filter.getString("gte");
    String gt = filter.getString("gt");
    String lt = filter.getString("lt");
    String lte = filter.getString("lte");
    String time_zone = filter.getString("time_zone");

    if (gte != null) {
        result.gte(gte);
    }
    if (gt != null) {
        result.gt(gt);
    }
    if (lt != null) {
        result.lt(lt);
    }
    if (lte != null) {
        result.lte(lte);
    }
    if (time_zone != null) {
        result.timeZone(time_zone);
    }
    return result;
}
项目:stash-codesearch-plugin    文件:SearchFilterUtils.java   
public FilterBuilder dateRangeFilter(ReadableInstant from, ReadableInstant to) {
    if (from == null && to == null) {
        return matchAllFilter();
    }
    RangeFilterBuilder dateFilter = rangeFilter("commit.commitdate");
    if (from != null) {
        dateFilter.gte(from.getMillis());
    }
    if (to != null) {
        dateFilter.lte(to.getMillis());
    }
    // Match all files as well, since they don't have date info (user can turn off by
    // unchecking "search files" option.)
    return orFilter(dateFilter, typeFilter("file"));
}
项目:elasticsearch-mapping-parent    文件:RangeFilterBuilderHelper.java   
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;
}
项目:bolton-sigmod2013-code    文件:ElasticSearchClient.java   
/**
 * Perform a range scan for a set of records in the database. Each
 * field/value pair from the result will be stored in a HashMap.
 *
 * @param table The name of the table
 * @param startkey The record key of the first record to read.
 * @param recordcount The number of records to read
 * @param fields The list of fields to read, or null for all of them
 * @param result A Vector of HashMaps, where each HashMap is a set
 * field/value pairs for one record
 * @return Zero on success, a non-zero error code on error. See this class's
 * description for a discussion of error codes.
 */
@Override
public int scan(String table, String startkey, int recordcount, Set<String> fields, Vector<HashMap<String, ByteIterator>> result) {
    try {
        final RangeFilterBuilder filter = rangeFilter("_id").gte(startkey);
        final SearchResponse response = client.prepareSearch(indexKey)
                .setTypes(table)
                .setQuery(matchAllQuery())
                .setFilter(filter)
                .setSize(recordcount)
                .execute()
                .actionGet();

        HashMap<String, ByteIterator> entry;

        for (SearchHit hit : response.getHits()) {
            entry = new HashMap<String, ByteIterator>(fields.size());

            for (String field : fields) {
                entry.put(field, new StringByteIterator((String) hit.getSource().get(field)));
            }

            result.add(entry);
        }

        return 0;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 1;
}
项目:geeCommerce-Java-Shop-Software-and-PIM    文件:DefaultElasticsearchHelper.java   
@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));
    }

}
项目:usergrid    文件:EsQueryVistor.java   
@Override
public void visit( LessThan op ) throws NoIndexException {
    final String name = op.getProperty().getValue().toLowerCase();
    final Object value = op.getLiteral().getValue();


    final RangeFilterBuilder termQuery =
            FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lt(sanitize(value));


    queryBuilders.push( NoOpQueryBuilder.INSTANCE );

    //we do this by query, push empty

    filterBuilders.push( fieldNameTerm( name, termQuery ) );
}
项目:usergrid    文件:EsQueryVistor.java   
@Override
public void visit( LessThanEqual op ) throws NoIndexException {
    final String name = op.getProperty().getValue().toLowerCase();
    final Object value = op.getLiteral().getValue();


    final RangeFilterBuilder termQuery =
            FilterBuilders.rangeFilter( getFieldNameForType( value ) ).lte(sanitize(value));


    queryBuilders.push( NoOpQueryBuilder.INSTANCE );

    filterBuilders.push( fieldNameTerm( name, termQuery ) );
}
项目:usergrid    文件:EsQueryVistor.java   
@Override
public void visit( GreaterThan op ) throws NoIndexException {
    final String name = op.getProperty().getValue().toLowerCase();
    final Object value = op.getLiteral().getValue();


    final RangeFilterBuilder rangeQuery =
            FilterBuilders.rangeFilter( getFieldNameForType( value ) ).gt(sanitize(value));

    filterBuilders.push( fieldNameTerm( name, rangeQuery ) );

    queryBuilders.push( NoOpQueryBuilder.INSTANCE );
}
项目:usergrid    文件:EsQueryVistor.java   
@Override
public void visit( GreaterThanEqual op ) throws NoIndexException {
    String name = op.getProperty().getValue().toLowerCase();
    Object value = op.getLiteral().getValue();


    final RangeFilterBuilder rangeQuery =
            FilterBuilders.rangeFilter( getFieldNameForType( value ) ).gte(sanitize(value));

    filterBuilders.push(fieldNameTerm(name, rangeQuery));

    queryBuilders.push( NoOpQueryBuilder.INSTANCE );
}
项目:eservice    文件:IElasticQueryBuilder.java   
/**
 * Allows you to add and configure a range filter for the specified propertyName
 * @param propertyName
 * @return
 */
RangeFilterBuilder withRangeFilter(String propertyName);