我想知道,如果有一种方法可以使用2列而不是一列来对查询进行排序。我很确定query.order("param1").order("param2")
忽略了一个参数。
是否可以使用具有多列的objectify进行排序?
这是我的@Entity
@Entity
public class Operation {
@Id protected Long id;
@Index protected Long creatorId;
@Index protected Long categoryId;
@Index protected Double value;
@Index protected String description;
@Index protected Date date;
}
答案 0 :(得分:2)
可以使用具有多个列的objectify进行排序。 实际上,如果您有正确的多属性索引,那么您的问题中的查询应该有效。
例如,如果您想按日期和creatorId排序结果(从您的队列中获取这些字段),您需要在项目中使用以下索引" datastore-indexes.xml&#34 ;文件:
<datastore-index kind="Operation " ancestor="false">
<property name="date " direction="asc" />
<property name="creatorId" direction="asc" />
</datastore-index>
请注意,这只是一个例子。 &#34;祖先&#34;,&#34;方向&#34;的实际值取决于你的要求。
另一种选择是自动生成所需的索引。如果在GAE开发服务器上运行应用程序,开发服务器会自动生成带有所需索引的数据存储区索引文件(WEB-INF / appengine-generated / datastore-indexes-auto.xml)。
您可以详细了解here。