Skip to content

Commit 1f6e3db

Browse files
committed
Document natural sorting and the DATABASE_EMULATE_NATURAL_SORT option
1 parent 2fabcab commit 1f6e3db

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DATABASE_MYSQL_USE_SSL_CA=0
2424
DATABASE_MYSQL_SSL_VERIFY_CERT=1
2525

2626
# Emulate natural sorting of strings even on databases that do not support it (like SQLite, MySQL or MariaDB < 10.7)
27-
# This can be slow on big databases
27+
# This can be slow on big databases and might have some problems and quirks, so use it with caution
2828
DATABASE_EMULATE_NATURAL_SORT=0
2929

3030
###################################################################################

docs/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ options listed, see `.env` file for the full list of possible env variables.
4040
* `DATABASE_MYSQL_USE_SSL_CA`: If this value is set to `1` or `true` and a MySQL connection is used, then the connection
4141
is encrypted by SSL/TLS and the server certificate is verified against the system CA certificates or the CA certificate
4242
bundled with Part-DB. Set `DATABASE_MYSQL_SSL_VERIFY_CERT` if you want to accept all certificates.
43+
* `DATABASE_EMULATE_NATURAL_SORT` (default 0): If set to 1, Part-DB will emulate natural sorting, even if the database
44+
does not support it natively. However this is much slower than the native sorting, and contain bugs or quirks, so use
45+
it only, if you have to.
4346
* `DEFAULT_LANG`: The default language to use server-wide (when no language is explicitly specified by a user or via
4447
language chooser). Must be something like `en`, `de`, `fr`, etc.
4548
* `DEFAULT_TIMEZONE`: The default timezone to use globally, when a user has no timezone specified. Must be something

docs/installation/choosing_database.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,29 @@ If you want to use a unix socket for the connection instead of a TCP connnection
154154
```shell
155155
DATABASE_URL="postgresql://db_user:db_password@localhost/db_name?serverVersion=12.19&charset=utf8&unix_socket=/var/run/postgresql/.s.PGSQL.5432"
156156
```
157+
158+
159+
## Natural Sorting
160+
161+
Natural sorting is the sorting of strings in a way that numbers are sorted by their numerical value, not by their ASCII value.
162+
163+
For example in the classical binary sorting the string `DIP-4`, `DIP-8`, `DIP-16`, `DIP-28` would be sorted as following:
164+
165+
* `DIP-16`
166+
* `DIP-28`
167+
* `DIP-4`
168+
* `DIP-8`
169+
170+
In natural sorting, it would be sorted as:
171+
172+
* `DIP-4`
173+
* `DIP-8`
174+
* `DIP-16`
175+
* `DIP-28`
176+
177+
Part-DB can sort names in part tables and tree views naturally. PostgreSQL and MariaDB 10.7+ support natural sorting natively,
178+
and it is automatically used if available.
179+
180+
For SQLite and MySQL < 10.7 it has to be emulated if wanted, which is pretty slow. Therefore it has to be explicity enabled by setting the
181+
`DATABASE_EMULATE_NATURAL_SORT` environment variable to `1`. If it is 0 the classical binary sorting is used, on these databases. The emulations
182+
might have some quirks and issues, so it is recommended to use a database which supports natural sorting natively, if you want to use it.

0 commit comments

Comments
 (0)