如何在Objectify中对响应进行排序? [英] How to sort responses in Objectify?

查看:97
本文介绍了如何在Objectify中对响应进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Objectify 3.1构建一个部署到GAE的应用程序。我尝试使用order()子句进行查询时遇到了奇怪的结果。



我的域名:

  
public class InvoiceLineItem
{
private int units;

私人BigDecimal unitCost;
私人BigDecimal extendedCost;

私人字符串描述;

@Parent Key<发票>发票;
}

我试图收集与给定发票相关联的所有InvoiceLineItems,以下内容:

  ofy().query(InvoiceLineItem.class).ancestor(invoiceKey).list(); 

在我的测试案例中,这很好,按预期返回2行。 b
$ b

但是,当我尝试为上述查询添加排序顺序时,如下所示:

  ofy().query(InvoiceLineItem.class).ancestor(invoiceKey).order(+ description)。list(); 

我总是得到0个结果。我试着改变顺序的方向,字段的排序顺序,查询中order()子句的位置,全部无效。任何人都可以看到我在这里做的任何错误?



谢谢...

解决方案

这里有几个潜在的问题:


  • description字段必须被索引

  • description字段必须小于500个字符,因为超过500个字符会转换为 Text ,这是不可索引的

  • 摆脱+。它是.order(description)或.order( - description)。


I'm currently building an app for deployment to GAE, using Objectify 3.1. I am getting strange results when attempting to do a query with an order() clause.

My domain:


public class InvoiceLineItem
{
    private int units;

    private BigDecimal unitCost;
    private BigDecimal extendedCost;

    private String description;

    @Parent Key<Invoice> invoice;
}

I am attempting to gather all of the InvoiceLineItems associated with a given Invoice using the following:

ofy ().query (InvoiceLineItem.class).ancestor (invoiceKey).list ( );

In my test case, this works just fine, returning 2 rows as expected.

However, when I try to add a sort order to the above query, like so:

ofy ().query (InvoiceLineItem.class).ancestor (invoiceKey).order ("+description").list ();

I always get 0 results. I've tried changing the order direction, the field its ordering by, the location of the order () clause in the query, all to no effect. Can anyone see anything that I'm doing wrong here?

Thanks...

解决方案

There are a couple potential issues here:

  • The description field must be indexed
  • The description field must be less than 500 chars, because over 500 chars gets converted to a Text which is not indexable
  • Get rid of the +. It's either .order("description") or .order("-description").

这篇关于如何在Objectify中对响应进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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