https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885

--- Comment #2 from David Nind <[email protected]> ---
Created attachment 208765
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208765&action=edit
Bug 43885: Do not sort on a non-existent field in Elasticsearch

QueryBuilder::_sort_field appended "__sort" to any field that was not
recorded as not sortable. As get_elasticsearch_mappings only recorded
the sortable fields in sort_fields, a field configured as not sortable
was treated like an unknown one and also got "__sort" appended. That
field does not exist in the index, so Elasticsearch rejected the whole
query ("No mapping found for [cn-sort__sort] in order to sort on") and
the search failed. With defaultSortField or OPACdefaultSortField set to
such a field, every search failed.

This patch:
- records the fields without a sort mapping in sort_fields too (as 0,
  unless another mapping of the same field is sortable), so that
  _sort_field sorts them on their search field, using the .raw version
  of text fields, as the code already intended
- makes _sort_field return undef, with a warning, for fields that are
  not mapped at all, and build_query skips that sort, so the results
  are sorted by relevance instead of failing

Steps to follow:
1. Administration > Search engine configuration (Elasticsearch): set
   "Sortable" to No for cn-sort and save.
2. Rebuild the index so that the mapping is recreated:
   misc/search_tools/rebuild_elasticsearch.pl -d -b
3. Search the staff interface and sort by call number: the search fails
   ("Unable to perform your search"), and the logs show
   "No mapping found for [cn-sort__sort] in order to sort on".
4. Set OPACdefaultSortField to "call number" and search the OPAC: the
   search fails.
5. Apply the patch and restart Plack if running under it.
6. Repeat steps 3 and 4: the searches work and the results are sorted
   by call number (ascending and descending).
7. Restore "Sortable" to Yes for cn-sort, rebuild the index as in step 2
   and restore OPACdefaultSortField.
8. prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t \
         t/db_dependent/Koha/SearchEngine/Elasticsearch.t

Signed-off-by: Adolfo Rodríguez <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: David Nind <[email protected]>

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to