简体   繁体   English

Objectify Google DataSore查询

[英]Objectify Google DataSore Query

Here's the thing :-) We have two classes, Appointment and Hairdresser , both having the same, one ancestor (a static final Key: topParent ) representing the HairSalon Key. 事情是这样的:-)我们有两个类, AppointmentHairdresser ,它们具有相同的类,一个祖先(一个静态的最终键: topParent )代表HairSalon键。 The Appointment contains the Hairdresser like this: Appointment包含如下的Hairdresser

    @Parent
    public Key parent; 
    public Key hairdresserKey;`


but when we try to filter out the appointment, it doesn't come up with a result. 但是当我们尝试过滤约会时,它不会得出结果。 The parent in the hairdresserKey == null , that might be a clue, but we're kind of stuck now. hairdresserKey == null的父级可能是一个线索,但是现在我们有点卡住了。

So can someone please tell us what's wrong with this query? 那么有人可以告诉我们此查询出了什么问题吗?

Thanks a lot! 非常感谢!

        appointment.hairdresserKey = new Key<Hairdresser>(topParent, Hairdresser.class, appointment.hairdresser.id);
    appointment.parent = topParent;

    Key<Hairdresser> queryKey = new Key<Hairdresser>(topParent, Hairdresser.class, appointment.hairdresser.id);

    Objectify ofyTransaction = ObjectifyService.beginTransaction();
    try {

        List<Key<Appointment>> previousTimeSlotOneHour = ofyTransaction.query(Appointment.class)
                .ancestor(topParent)
                .filter("hairdresserKey", appointment.hairdresserKey)
                .filter("timeSlot", appointment.timeSlot.getPreviousTimeSlot())
                .filter("LENGTH", 1.0d).listKeys();

To clearify some more, this is how Appointment set up: 为了进一步说明,这是约会设置的方式:

@Unindexed

public class Appointment implements Serializable { 公共类约会实现Serializable {

@Id
public Long id;
@Indexed
public TimeSlot timeSlot;

@Transient
public WorkDay workDay;

@Transient
public Customer customer;
public Key customerKey;

public int END_TIME_HOUR;
public int END_TIME_MINUTES;

@Indexed
public TREATMENT treatment = TREATMENT.TREATMENT_CUT;
public int revisionNumber = -1;

/* QUERY Fields */
@Indexed
private String stringDate;
private double LENGTH;

@Parent
public Key parent;
private Date date;

@Transient
public Hairdresser hairdresser;
public Key hairdresserKey;

Found this: 发现了这一点:

This is almost certainly an indexing issue. 这几乎可以肯定是一个索引问题。 In order for that query to work, you must define two indexes: 为了使该查询起作用,必须定义两个索引:

A single-property index on referenceKeyToC A multi-property index on {ancestor, referenceKeyToC} In Objectify 3.x, properties have single-property indexes by default, but if you have added @Unindexed to the class B then you need to put @Indexed on referenceKeyToC. 在referenceKeyToC上的单属性索引在{ancestor,referenceKeyToC}上的多属性索引在Objectify 3.x中,属性默认情况下具有单属性索引,但是如果将@Unindexed添加到类B,则需要将@在referenceKeyToC上建立索引。 The multi-property index is defined in datastore-indexes.xml. 多属性索引在datastore-indexes.xml中定义。 If you run this query in dev mode, the environment should provide you with the snippet of xml needed. 如果您以开发人员模式运行此查询,则环境应为您提供所需的xml代码段。

That did the trick! 这奏效了! Thanks for pointing in the right direction! 感谢您指出正确的方向!

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

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