1

How to sort a resultset by date (unixtime)?

search post {
    document post {
        field created type long {
            indexing: summary | attribute
        }
        field description type string {
            indexing: summary | index
        }
    }
    rank-profile date inherits default {
        first-phase {
            expression: attribute(created)
        }
    }
}

curl:

curl -s -H "Content-Type: application/json" --data
    '{"yql" : "select * from post where description contains \"computer\";","ranking":"date"}'
    http://localhost:8080/search/ | jq .

The resultset is not sorted by 'created'. And 'relevance' is always zero:

{
    "id": "id:post:post::1",
    "relevance": 0,
    "source": "content",
    "fields": {...}
}
doublemax
  • 443
  • 1
  • 4
  • 11

1 Answers1

4

For straight forward sorting on long attributes, it would be more efficient to use the sorting/ordering functionality rather than the more powerful, yet more expensive ranking framework.

As mentioned in the sorting documentation, it is recommended to use the built-in unranked ranking profile for queries with sorting/ordering. Also, I'm not sure the ranking alias is allowed when using the JSON query language - I believe you would need to use the full ranking.profile parameter which is nested in JSON.

Your curl would then look something like:

curl -s -H "Content-Type: application/json" --data
    '{"yql" : "select * from post where description contains \"computer\" order by created desc;","ranking": { "profile" : "unranked" } }'
    http://localhost:8080/search/ | jq .
Frode Lundgren
  • 336
  • 1
  • 4