[Bug]: API won't sort by media.metadata.titleIgnorePrefix #2700

Open
opened 2026-04-25 00:09:41 +02:00 by adam · 5 comments
Owner

Originally created by @chelming on GitHub (Apr 1, 2025).

What happened?

When calling the /items API with a sort of media.metadata.titleIgnorePrefix the sort is ignored and seems to be returned oldest-added to newest-added. Other sorts work just fine like media.metadata.authorNameLF

"/api/libraries/2fa94552-0683-44c0-929e-70a0c9766352/items?sort=media.metadata.titleIgnorePrefix" | jq '.results[] | (.addedAt|tostring) + " " + .media.metadata.titleIgnorePrefix'

"1740031330413 Unwanted Guest, The"
"1741006109688 Infinity Alchemist"
"1741084671226 Oathbound"
"1742043548118 Jasmine Throne, The"
"1742043548824 Oleander Sword, The"
"1742157199465 Lotus Empire, The"
"1742157743596 Go Luck Yourself"

What did you expect to happen?

I expected the results to be returned sorted by media.metadata.titleIgnorePrefix

Steps to reproduce the issue

  1. In the UI, make sure "Ignore prefixes when sorting info" is disabled
  2. Get an API token from the User's page
  3. Query the API: "/api/libraries/{some_libary_id}/items?sort=media.metadata.titleIgnorePrefix"
  4. Parse the response with JQ:

Audiobookshelf version

v2.20.0

How are you running audiobookshelf?

Docker

What OS is your Audiobookshelf server hosted from?

Linux

If the issue is being seen in the UI, what browsers are you seeing the problem on?

None

Logs

2025-04-01 00:20:15.356

DEBUG

Set Log Level to DEBUG

2025-04-01 00:20:15.367

DEBUG

[ApiCacheManager] Array.afterUpsert: Clearing cache

2025-04-01 00:20:21.819

DEBUG

[ApiCacheManager] count: 0 size: 0

2025-04-01 00:20:21.826

DEBUG

[LibraryItemsBookFilters] countCacheKey: {"where":{"0":{}},"distinct":true,"attributes":null,"replacements":{},"include":{"0":{"model":"libraryItem","required":true,"where":{"libraryId":"2fa94552-0683-44c0-929e-70a0c9766352"},"include":{}},"1":{"model":"bookSeries","attributes":{"0":"id","1":"seriesId","2":"sequence","3":"createdAt"},"include":{"model":"series","attributes":{"0":"id","1":"name","2":"nameIgnorePrefix"}},"order":{"0":{"0":"createdAt","1":"ASC"}},"separate":true},"2":{"model":"bookAuthor","attributes":{"0":"authorId","1":"createdAt"},"include":{"model":"author","attributes":{"0":"id","1":"name"}},"order":{"0":{"0":"createdAt","1":"ASC"}},"separate":true}},"order":{},"subQuery":false}

2025-04-01 00:20:22.126

DEBUG

Loaded 246 of 246 items for libary page in 0.30s

2025-04-01 00:20:22.135

DEBUG

[ApiCacheManager] Cache miss: {"user":"chris","url":"/libraries/2fa94552-0683-44c0-929e-70a0c9766352/items?sort=media.metadata.titleIgnorePrefix"}

Additional Notes

No response

Originally created by @chelming on GitHub (Apr 1, 2025). ### What happened? When calling the /items API with a sort of `media.metadata.titleIgnorePrefix` the sort is ignored and seems to be returned oldest-added to newest-added. Other sorts work just fine like `media.metadata.authorNameLF` ``` "/api/libraries/2fa94552-0683-44c0-929e-70a0c9766352/items?sort=media.metadata.titleIgnorePrefix" | jq '.results[] | (.addedAt|tostring) + " " + .media.metadata.titleIgnorePrefix' "1740031330413 Unwanted Guest, The" "1741006109688 Infinity Alchemist" "1741084671226 Oathbound" "1742043548118 Jasmine Throne, The" "1742043548824 Oleander Sword, The" "1742157199465 Lotus Empire, The" "1742157743596 Go Luck Yourself" ``` ### What did you expect to happen? I expected the results to be returned sorted by media.metadata.titleIgnorePrefix ### Steps to reproduce the issue 1. In the UI, make sure "Ignore prefixes when sorting info" is disabled 2. Get an API token from the User's page 3. Query the API: "/api/libraries/{some_libary_id}/items?sort=media.metadata.titleIgnorePrefix" 4. Parse the response with JQ: ### Audiobookshelf version v2.20.0 ### How are you running audiobookshelf? Docker ### What OS is your Audiobookshelf server hosted from? Linux ### If the issue is being seen in the UI, what browsers are you seeing the problem on? None ### Logs ```shell 2025-04-01 00:20:15.356 DEBUG Set Log Level to DEBUG 2025-04-01 00:20:15.367 DEBUG [ApiCacheManager] Array.afterUpsert: Clearing cache 2025-04-01 00:20:21.819 DEBUG [ApiCacheManager] count: 0 size: 0 2025-04-01 00:20:21.826 DEBUG [LibraryItemsBookFilters] countCacheKey: {"where":{"0":{}},"distinct":true,"attributes":null,"replacements":{},"include":{"0":{"model":"libraryItem","required":true,"where":{"libraryId":"2fa94552-0683-44c0-929e-70a0c9766352"},"include":{}},"1":{"model":"bookSeries","attributes":{"0":"id","1":"seriesId","2":"sequence","3":"createdAt"},"include":{"model":"series","attributes":{"0":"id","1":"name","2":"nameIgnorePrefix"}},"order":{"0":{"0":"createdAt","1":"ASC"}},"separate":true},"2":{"model":"bookAuthor","attributes":{"0":"authorId","1":"createdAt"},"include":{"model":"author","attributes":{"0":"id","1":"name"}},"order":{"0":{"0":"createdAt","1":"ASC"}},"separate":true}},"order":{},"subQuery":false} 2025-04-01 00:20:22.126 DEBUG Loaded 246 of 246 items for libary page in 0.30s 2025-04-01 00:20:22.135 DEBUG [ApiCacheManager] Cache miss: {"user":"chris","url":"/libraries/2fa94552-0683-44c0-929e-70a0c9766352/items?sort=media.metadata.titleIgnorePrefix"} ``` ### Additional Notes _No response_
adam added the bug label 2026-04-25 00:09:41 +02:00
Author
Owner

@chelming commented on GitHub (Apr 1, 2025):

looks like the same happens for /series with nameIgnorePrefix

@chelming commented on GitHub (Apr 1, 2025): looks like the same happens for `/series` with `nameIgnorePrefix`
Author
Owner

@advplyr commented on GitHub (Apr 2, 2025):

This is happening here:
https://github.com/advplyr/audiobookshelf/blob/96825c3c2b199b41975d3ee8a5266ed36288d1ab/server/utils/queries/libraryItemsBookFilters.js#L270-L279

It is looking at the server setting to determine which to use.

This is different from authorNameLF which doesn't require a server setting.

It could be changed to require the clients to check the server setting before making the request but I prefer not doing that.

Another option is adding an override query param. What is the use-case for this?

@advplyr commented on GitHub (Apr 2, 2025): This is happening here: https://github.com/advplyr/audiobookshelf/blob/96825c3c2b199b41975d3ee8a5266ed36288d1ab/server/utils/queries/libraryItemsBookFilters.js#L270-L279 It is looking at the server setting to determine which to use. This is different from `authorNameLF` which doesn't require a server setting. It could be changed to require the clients to check the server setting before making the request but I prefer not doing that. Another option is adding an override query param. What is the use-case for this?
Author
Owner

@chelming commented on GitHub (Apr 2, 2025):

Building an OPDS feed that uses the API

@chelming commented on GitHub (Apr 2, 2025): Building an OPDS feed that uses the API
Author
Owner

@chelming commented on GitHub (Apr 2, 2025):

Shouldn't the fallback for sort=media.metadata.titleIgnorePrefix be the server setting for global.ServerSettings.sortingIgnorePrefix and not addedAt?

@chelming commented on GitHub (Apr 2, 2025): Shouldn't the fallback for `sort=media.metadata.titleIgnorePrefix` be the server setting for `global.ServerSettings.sortingIgnorePrefix` and not `addedAt`?
Author
Owner

@chelming commented on GitHub (Apr 2, 2025):

e.g.,

❯ curl -H "Authorization: Bearer SSBsb3ZlIGFkdnB5ciBhbmQgYXVkaW9ib29rc2hlbGY=" "https://boodioaudioshelf.dev/api/libraries/2fa94552-0683-44c0-929e-70a0c9766352/items?sort=media.metadata.titleIgnorePrefix" | jq '.results[] | "added
 at: " + (.addedAt|tostring) + " - " + .media.metadata.titleIgnorePrefix'                                                                                                            
                                                                                                     
"added at: 1662407024381 - Salacious Hotties"
"added at: 1662474256321 - Secrets to Huge Biceps, The"
"added at: 1662474820027 - Magnificent NodeJS Dev, The"
"added at: 1669685136821 - Long Book About Why Python Is Better, A"
"added at: 1669685185535 - Joke, Sorry, A"
"added at: 1675733286845 - Kingdom of Antelopes"
"added at: 1675733294956 - Empire of Swifties"
"added at: 1675733313993 - Queen of San Diego"
"added at: 1677080926537 - Children of Tim"
@chelming commented on GitHub (Apr 2, 2025): e.g., ``` ❯ curl -H "Authorization: Bearer SSBsb3ZlIGFkdnB5ciBhbmQgYXVkaW9ib29rc2hlbGY=" "https://boodioaudioshelf.dev/api/libraries/2fa94552-0683-44c0-929e-70a0c9766352/items?sort=media.metadata.titleIgnorePrefix" | jq '.results[] | "added at: " + (.addedAt|tostring) + " - " + .media.metadata.titleIgnorePrefix' "added at: 1662407024381 - Salacious Hotties" "added at: 1662474256321 - Secrets to Huge Biceps, The" "added at: 1662474820027 - Magnificent NodeJS Dev, The" "added at: 1669685136821 - Long Book About Why Python Is Better, A" "added at: 1669685185535 - Joke, Sorry, A" "added at: 1675733286845 - Kingdom of Antelopes" "added at: 1675733294956 - Empire of Swifties" "added at: 1675733313993 - Queen of San Diego" "added at: 1677080926537 - Children of Tim" ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#2700