简体   繁体   English

如何使用应用引擎数据存储区查询的复合过滤器?

[英]How to use the composite filter of app-engine data store queries?

I have the this function: 我有这个功能:

@Override
  public List<Expense> getExpensesBetween(Date firstDate, Date secondDate) {

    Query query = new Query(expenseEntityKind);

    query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, secondDate);

    query.addFilter("date", Query.FilterOperator.GREATER_THAN_OR_EQUAL, firstDate);

    Iterable<Entity> entities = service.prepare(query).asIterable();

    return getReturnedExpenses(entities);
  }

I want to return all the expenses between two date ie greater than or equal 2012-05-01 AND less than or equal 2012-06-01. 我想退回两个日期(即大于或等于2012-05-01且小于或等于2012-06-01)之间的所有费用。 I took a look at the documentations of Google app-engine. 我看了一下Google应用程序引擎的文档 It says that we must use Composite Filters. 它说我们必须使用复合过滤器。 Google documentations: " However, if you want to set more than one filter on a query, you must use CompositeFilter . You must have at least two filters to use CompositeFilter . However, this documentations seems to be old and i didn't find any function called setFilter(); . Any suggestion how to create a composite filter ? I use App-engine sdk 1.6.6. Thanks in advance. Google文档:“但是,如果要在一个查询上设置多个过滤器,则必须使用CompositeFilter 。必须至少有两个过滤器才能使用CompositeFilter 。但是,此文档似乎很旧,我没有找到任何文档。函数setFilter();关于如何创建复合过滤器的任何建议?我使用App-engine sdk 1.6.6。

The following is taken from https://cloud.google.com/appengine/docs/java/datastore/queries which might be helpful here 以下内容摘自https://cloud.google.com/appengine/docs/java/datastore/queries ,这可能对您有所帮助

Filter heightMinFilter =
  new FilterPredicate("height",
                      FilterOperator.GREATER_THAN_OR_EQUAL,
                      minHeight);

Filter heightMaxFilter =
  new FilterPredicate("height",
                      FilterOperator.LESS_THAN_OR_EQUAL,
                      maxHeight);

//Use CompositeFilter to combine multiple filters
Filter heightRangeFilter =
  CompositeFilterOperator.and(heightMinFilter, heightMaxFilter);

The documentation you are looking is for the newest version (1.7.0). 您正在寻找的文档是最新版本(1.7.0)。 That features have been just introduced. 该功能刚刚被引入。 Here an example of how to use CompositeFilter (1.7.0 also). 这里是一个如何使用CompositeFilter的示例(也是1.7.0)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM