Peter
Peter

Reputation: 119

GAE Search API: Default value in order SortExpression

When setting sorting order option in SortExpression.Builder, it's strictly required to set a defaultValue(String,Numeric or Date).

What is a purpose of this setting and how it affects search results or result sorting order?

Upvotes: 1

Views: 414

Answers (1)

Haldean Brown
Haldean Brown

Reputation: 12721

Documents in the index are not required to all have the same fields. If you try to sort on a field that some documents do not contain, we use the appropriate default value for that document. For example, if I had the following documents:

doc A: NumberField(name=x, value=7), TextField(name=y, value="hello")
doc B: NumberField(name=x, value=20), TextField(name=y, value="world")
doc C: TextField(name=y, value="hello")  

In this case, if we sort on the field x with a default numeric value of 10, we get A, C, B, but if the default numeric value is 0, we get C, A, B.

Upvotes: 1

Related Questions