feat(search): add configurable sorting for submission results
All checks were successful
Build and Publish Docker Image / deploy (push) Successful in 1m17s

Introduce a `sort` query parameter in submission search paths and pass it into
store search logic. Matching results can now be ordered by `newest`, `oldest`,
`score_desc`, `score_asc`, `mops_desc`, or `mops_asc`, with invalid values
safely defaulting to `newest`.

Update README and HTTP examples to document the new sort behavior and usage so
clients can control result ordering server-side without extra post-processing.feat(search): add configurable sorting for submission results

Introduce a `sort` query parameter in submission search paths and pass it into
store search logic. Matching results can now be ordered by `newest`, `oldest`,
`score_desc`, `score_asc`, `mops_desc`, or `mops_asc`, with invalid values
safely defaulting to `newest`.

Update README and HTTP examples to document the new sort behavior and usage so
clients can control result ordering server-side without extra post-processing.
This commit is contained in:
2026-04-16 00:05:21 +03:00
parent ec86119088
commit c8323d1b6a
5 changed files with 251 additions and 73 deletions

View File

@@ -5,8 +5,9 @@ Production-oriented Go web application for ingesting CPU benchmark results, stor
## Features
- `POST /api/submit` accepts either `application/json` or `multipart/form-data`.
- `GET /api/search` performs case-insensitive token matching against submitter/general fields and CPU brand strings, with explicit thread-mode, platform, intensity, and duration filters.
- `GET /api/search` performs case-insensitive token matching against submitter/general fields and CPU brand strings, with explicit thread-mode, platform, intensity, duration, and sort controls.
- `GET /` renders the latest submissions with search and pagination.
- The dashboard follows the system light/dark preference by default and includes a manual theme toggle in the top-right corner.
- BadgerDB stores each submission under a reverse-timestamp key so native iteration returns newest records first.
- A startup-loaded in-memory search index prevents full DB deserialization for every query.
- Graceful shutdown closes the HTTP server and BadgerDB cleanly to avoid lock issues.
@@ -123,13 +124,14 @@ Query parameters:
- `cpu`: token-matches `cpuInfo.brandString`
- `thread`: `single` or `multi`
- `platform`: `windows`, `linux`, or `macos`
- `sort`: `newest`, `oldest`, `score_desc`, `score_asc`, `mops_desc`, or `mops_asc`
- `intensity`: exact match on `config.intensity`
- `durationSecs`: exact match on `config.durationSecs`
Example:
```bash
curl "http://localhost:8080/api/search?text=intel&cpu=13700&thread=multi&platform=windows&intensity=10&durationSecs=30"
curl "http://localhost:8080/api/search?text=intel&cpu=13700&thread=multi&platform=windows&sort=score_desc&intensity=10&durationSecs=30"
```
### `GET /`
@@ -141,6 +143,7 @@ Query parameters:
- `cpu`
- `thread`
- `platform`
- `sort`
- `intensity`
- `durationSecs`
@@ -149,7 +152,7 @@ Examples:
```text
http://localhost:8080/
http://localhost:8080/?page=2
http://localhost:8080/?text=anonymous&cpu=ryzen&thread=multi&platform=windows&intensity=10&durationSecs=20
http://localhost:8080/?text=anonymous&cpu=ryzen&thread=multi&platform=windows&sort=score_desc&intensity=10&durationSecs=20
```
## Request Examples
@@ -186,7 +189,7 @@ curl -X POST "http://localhost:8080/api/submit" \
- canonical submission payload
- normalized general search text
- normalized CPU brand text
- Searches scan the in-memory ordered slice rather than reopening and deserializing Badger values for every request, and apply explicit platform, thread-mode, intensity, and duration filters in memory.
- Searches scan the in-memory ordered slice rather than reopening and deserializing Badger values for every request, apply explicit platform, thread-mode, intensity, and duration filters in memory, then optionally sort the matching results by submission time, score, or MOps/sec.
## Docker