Document sorting on dummy fields

Created on 30 August 2023, over 1 year ago
Updated 4 September 2023, over 1 year ago

Created a dummy field. Managing its data via hook_search_api_solr_documents_alter. This all works.
Only problem is, in the views, it doesn't seem to be sorting based on dummy field properly.

📌 Task
Status

Active

Version

4.0

Component

Documentation

Created by

🇬🇧United Kingdom mirhamzah

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mirhamzah
  • 🇩🇪Germany mkalkbrenner 🇩🇪

    Which field type did you select?

  • 🇬🇧United Kingdom mirhamzah

    String

  • 🇩🇪Germany mkalkbrenner 🇩🇪

    turn on search_api_solr_devel and check the sort parameters. Is the field missing? Or is it wrong?

  • 🇬🇧United Kingdom mirhamzah

    That is all good, but turning on search_api_solr_devel helped me debug in right direction.

    The fields sort_X3b_en_FIELD_NAME and sort_X3b_und_FIELD_NAME had default data, not the overridden data.
    Not sure if it is meant to be like that or there is a setting to override data for sorting.

    I had just this line before:

    $document->setField('sm_FIELD_NAME', $value);
    

    Added couple more lines for sorting and now it looks like this:

    $document->setField('sm_FIELD_NAME', $value);
    
    $document->setField('sort_X3b_en_FIELD_NAME', $value);
    $document->setField('sort_X3b_und_FIELD_NAME', $value);
    

    And it seems to be working fine.

    Thanks :)

  • 🇩🇪Germany mkalkbrenner 🇩🇪

    Yes, we have language specific sort fields, because collations differ from language to language.
    These sort fields are generated internally. But in you case they get filled before you replace the dummy value. At least we should document that behaviour.

Production build 0.71.5 2024