App Engine数据存储-复合索引-数据存储索引-不起作用 [英] App Engine DataStore - Compound Indexes - datastore-indexes - not working

查看:77
本文介绍了App Engine数据存储-复合索引-数据存储索引-不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用复合索引搜索实体.我正在使用Objectify 4.

I am unable to search entities using compound indexes. I am using Objectify 4.

实体配置:

@Entity
@Unindex
class MyEntity implements Serialiable
{
    @Id String id;
    String one;
    String two;
    long three;
}

索引配置:

<datastore-indexes autoGenerate="true">
    <datastore-index kind="MyEntity" ancestor="false">
        <property name="one" direction="asc" />
        <property name="two" direction="desc" />
    </datastore-index>
</datastore-indexes>

我看到内置在DataStore Indexes中的索引.但是,当我使用以下查询进行搜索时,总是得到空结果.

I see the indexes built in DataStore Indexes. However, when I search using the following query, I always get empty results.

Objectify ofy = ObjectifyService.ofy();
Query<MyEntity> query = ofy.loader()
                           .type(MyEntity.class)
                           .filter("one", "value-one")
                           .filter("two", "value-two");
List<MyEntity> result = query.list();

response.getWriter().println("Size: " + result.size());
//^^ this is always "0" ^^

我正在使用HRD.

有人猜怎么了?顺便说一句,它曾经工作到很早以前……早在上周.现在,它在开发服务器和实际服务器上均不起作用.

Any guesses what's going wrong? btw, it used to work until some time back... as early as last week. Now, it doesn't work on dev-server as well as on actual servers.

推荐答案

复合索引需要对所有涉及的属性进行索引:

Compound indexes needs all properties involved to be indexed:

@Entity
class MyEntity implements Serialiable
{
    @Id String id;
    @Index String one;
    @Index String two;
    long three;
}

在保存实体时未将字段标记为已索引,Objectify在保存这些实体时未在这些字段上进行索引,因此这就是GQL命令还返回0结果的原因.

As you are saving the entities without marking the fields as indexed, Objectify is saving those entities without INDEXING them on those fields, thats why your GQL command also return 0 results.

这篇关于App Engine数据存储-复合索引-数据存储索引-不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆