Why is my sort not working?

Hi. Im evaluating Manticore for use in a project but I cant get sorting to work. I have created an index with some fields, “name” and “description” among them. The query I am using looks like this:


{
    "index" : "my_index",
    "track_scores": true,
    "query":
    {
       "match_all": {}
    },
  "sort": [{"name": {"order": "asc"}}]
}

Yet, my result looks like this:

{
  "took": 0,
  "timed_out": false,
  "hits": {
    "total": 2,
    "total_relation": "eq",
    "hits": [
      {
        "_id": 3317499921795383302,
        "_score": 1,
        "_source": {
          "name": "B preset",
          "description": "This should be the second preset"
        }
      },
      {
        "_id": 3317499921795383301,
        "_score": 1,
        "_source": {
          "name": "a preset",
          "description": "This should be the first preset"
        }
      }
    ]
  }
}

Why is not “a preset” listed before “B preset”?

By default sorting of string attributes is case sensitive. (it NOT transformed as per charset_rules - if any)

Upper case is before lower case in ASCII encoding.

Instead may need collations to define sorting behaviour
https://manual.manticoresearch.com/Searching/Collations

You can probably define a ‘collation_server’ to define the default collation used by the server. You probably (at minimum) want libc_ci to get case insensitive sorting.

(with SQL mode, can be set per sesssion, dont know how to do that using the HTTP interface)

Ah, yes, this seems like it might be the case. Thank you for pointing me in the right direction.

Im not having any success with the collations. Neither setting collation_server in manticore conf nor using set collation_connection in sql mode changes anything.

Ensure that the fields you sort by are not only full-text fields but also string attributes, such as name text indexed attribute, e.g.:

➜  ~ mysql -P9306 -h0 -e "drop table if exists my_index; create table my_index(name text indexed attribute, description text); insert into my_index values(1, 'B preset', 'This should be the second preset'),(2, 'a preset', 'This should be the first preset')"

➜  ~ curl -s 0:9308/search -d '
{
    "index" : "my_index",
    "track_scores": true,
    "query":
    {
       "match_all": {}
    },
  "sort": [{"name": {"order": "asc"}}]
}'|jq .
{
  "took": 0,
  "timed_out": false,
  "hits": {
    "total": 2,
    "total_relation": "eq",
    "hits": [
      {
        "_id": 2,
        "_score": 1,
        "_source": {
          "name": "a preset",
          "description": "This should be the first preset"
        }
      },
      {
        "_id": 1,
        "_score": 1,
        "_source": {
          "name": "B preset",
          "description": "This should be the second preset"
        }
      }
    ]
  }
}

That did it. Thank you.