search icon indicating copy to clipboard operation
search copied to clipboard

[Core] apply to specify "always on" sort fields

Open dkarlovi opened this issue 6 years ago • 0 comments

Currently

Currently, we allow something like this:

$builder->add('@field', OrderType::class, ['default' => 'ASC']);

This means if you specify

User input Final query
name: foo name:foo; @field: ASC
name: foo; @field: desc name:foo; @field: DESC

Would like

$builder
    ->add('@id', OrderType::class, ['default' => 'ASC', 'always' => 'append'])
    ->add('@field', OrderType::class, ['default' => 'ASC']);

This means if you specify

User input Final query
name: foo name:foo; @field: ASC; @id: ASC
name: foo; @id: desc name:foo; @id: DESC
name: foo; @field: desc name:foo; @field: DESC; @id: ASC

So

  • the fields marked default would get appended if no user sort is given
  • the fields marked both default and always would get appended regarless of user input

This allows to stabilize order if you're sorting on a user-controllable property and all the values are the same, Elasticsearch will not keep the same order with each query.

dkarlovi avatar Feb 13 '19 12:02 dkarlovi