Bug 36633 - Support anti-the at REST API level
Summary: Support anti-the at REST API level
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: REST API (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement
Assignee: Bugs List
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-18 06:44 UTC by Jonathan Druart
Modified: 2025-12-29 20:10 UTC (History)
3 users (show)

See Also:
GIT URL:
Initiative type: ---
Sponsorship status: ---
Comma delimited list of Sponsors:
Crowdfunding goal: 0
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments
Bug 36633: Add anti-the support (3.99 KB, patch)
2024-04-22 14:20 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 36633: Add article-ignoring sort support to REST API (11.98 KB, patch)
2025-12-17 08:03 UTC, Martin Renvoize (ashimema)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2024-04-18 06:44:08 UTC
Coming from bug 35560.

If we migrate UI tables to DT using the REST API we need support the anti-the sorting type.
Comment 1 Jonathan Druart 2024-04-18 06:44:58 UTC
Martin, Tomas, did you think about that already?
Comment 2 Martin Renvoize (ashimema) 2024-04-19 23:37:19 UTC
Not thought about this at all yet, but it's a really sensible question.  I'll at as RT to ponder it.
Comment 3 Jonathan Druart 2024-04-22 14:20:06 UTC
Created attachment 165306 [details] [review]
Bug 36633: Add anti-the support
Comment 4 Jonathan Druart 2024-04-22 14:20:56 UTC
Patch for discussion (to apply on top of bug 35560)

It is suggesting to add a "modifier" to the order by attribute:
  +biblio.title/anti-the
the remove a, an, the.

Would that work? It's not really nice but I do not find something better for now.

TODO:
* tests
* escape $param (see FIXME)
* translatability of the stopwords
Comment 5 Jonathan Druart 2025-12-16 12:44:24 UTC
Martin, Tomas, ping?
Comment 6 Martin Renvoize (ashimema) 2025-12-16 17:00:18 UTC
I like the idea.

'anti-the' feels very 'koha' specific though.. I think what we're talking about here is known as 'natural sorting without articles' and the 'articles' are often defined as a stopwords list.

I wonder if we could improve this with definable 'stopwords' lists for different languages and use the term 'ignore-stopwords' or similar in the sort attribute.. even now it's not just 'the' being filtered.
Comment 7 Martin Renvoize (ashimema) 2025-12-17 08:03:37 UTC
Created attachment 190567 [details] [review]
Bug 36633: Add article-ignoring sort support to REST API

This patch adds support for ignoring leading articles (a, an, the, etc.)
when sorting via the Koha REST API using an /ignore-articles suffix modifier
on _order_by parameters.

We add a new system preference 'ArticleSortStopwords' (default: "a|an|the")
expecting a pipe-delimited list of articles to ignore when sorting.

Usage examples:
  GET /api/v1/biblios?_order_by=+biblio.title/ignore-articles
  GET /api/v1/biblios?_order_by=-biblio.title/ignore-articles

Test plan:
1. Apply patch and run database update
2. Run: prove t/db_dependent/Koha/REST/Plugin/Objects.t
3. Verify all tests pass
4. Test via REST API with /ignore-articles modifier
5. Configure ArticleSortStopwords system preference
6. Verify sorting ignores configured articles correctly
Comment 8 Martin Renvoize (ashimema) 2025-12-17 08:04:17 UTC
My proposed alternative
Comment 9 Katrin Fischer 2025-12-29 20:10:52 UTC
I like the idea of a configurable list.

I have been wondering about this bit:

+                'Pipe-delimited list of articles to ignore when sorting (e.g., a|an|the). Used by REST API /ignore-articles sort modifier and can be used by other sorting features. Articles are matched case-insensitively at the start of strings when followed by a space.',

Maybe it would be safer to ask people to add the space in the list, as I think it won't work with the space for some languages like Arabic and Hebrew (IIRC).
Maybe even French? (L'hotel ?)