Skip to content

feat: add the dict command for the dictionary admin API - #44

Merged
marevol merged 3 commits into
feat/add-ops-commandsfrom
feat/add-dict-commands
Oct 16, 2026
Merged

marevol merged 3 commits into
feat/add-ops-commandsfrom
feat/add-dict-commands

Conversation

@marevol

@marevol marevol commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the dict command for the dictionary admin API (/api/admin/dict):

  • fessctl dict list [--type TYPE] - the dictionary files (type, id, path, timestamp). Dictionary IDs come from here.
  • fessctl dict <type> list|get|create|update|delete|upload|download <dict_id> ... for synonym, mapping, kuromoji, stopwords, protwords and stemmeroverride.

The six types share one implementation (src/fessctl/commands/dict.py); each keeps the entry fields of its admin API form (synonym --source/--target -> inputs/outputs, mapping --source/--target -> inputs/output, kuromoji --token --segmentation --reading --pos, stopwords and protwords --word -> input, stemmeroverride --source/--target -> input/output). Repeatable options are sent one value per line.

  • update reads the entry first and sends back every field it was not asked to change (the PUT replaces the whole entry; the entries carry no version fields).
  • upload replaces a whole dictionary file, so it asks for confirmation unless --yes. download writes to standard output, or to --file (refuses to overwrite without --force).
  • --output text|json|yaml everywhere; non-zero exit on API failure.
  • The URL segment is stemmeroverride (lower case). The route comments in the Java say stemmerOverride, but only the lower-case path routes.
  • list_dict_items takes a type and a dictionary ID, so TestListPaging.test_every_list_method_puts_paging_in_body now passes placeholder values for required parameters of list_* methods (the only change to tests/unit/test_client.py).

Versions

The API, paths and fields are the same in 14.19.2, 15.6.1, 15.7.0, 15.8.0 and 15.9.0 (14.x uses PUT for create and POST for edit, which send_request already maps). Two differences:

  • Upload. 14.x and 15.9.0 take a multipart POST. 15.6.1, 15.7.0 and 15.8.0 only route PUT, and a multipart PUT is never parsed there ("File is required"), so no upload is possible; fessctl refuses it on those versions with an explanatory error. (15.9.0 also keeps the PUT route, which fails the same way.)
  • Create. Before 15.9 the response carries id "0" instead of the new entry's ID, and creating in an unknown dictionary reports success without storing anything; on 15.9 it fails.

Verified live

Against Fess 15.9.0 + fess-opensearch 3.9.0 (own compose stack): dict list (103 files), and for all six types create / get / list (paged) / update (partial, fields kept) / delete, with unique values and nothing left behind; error paths (unknown entry, unknown dictionary, duplicate and invalid values, missing option); download to stdout and to a file (byte-identical to the stored file; overwrite refusal and --force); upload and restore of a file (download equals the uploaded bytes), declined confirmation, missing file, unknown dictionary.

tests/commands/test_dict.py (10 tests: list, a CRUD flow per type, error paths, download/upload round trip that restores the file) passed 10/10 on 15.9.0, 15.8.0, 15.7.0, 15.6.1 and 14.19.2, through a stub conftest pointing at those servers. On 15.6.1 to 15.8.0 the upload test asserts the refusal instead. uv run pytest tests/unit: 221 passed.

Not verified

  • 15.6.1, 15.7.0 and 15.8.0 ran against the 15.9 stack's OpenSearch 3.9.0 rather than their paired engine versions (only 14.19.2 ran in its own compose with OpenSearch 2.19.1).
  • tests/commands/test_dict.py was not run through the repo's own fess_service compose fixture; it is import-checked (--collect-only) only.
  • Kuromoji upload and a very large mapping file were not exercised (upload was exercised on the protwords and stopwords files); the transfer timeout is 60 seconds.

Server oddities seen (not changed here)

  • Entry IDs are positions in the file: deleting an entry shifts later IDs, and there is no version field, so update/delete by ID can hit a different entry after a concurrent change.
  • On 15.9, a mapping created without output returns success with id "0" and stores nothing (the CLI requires --target).
  • Before 15.9, a comma in a synonym source gives a server error (error_code:..., status 2); 15.9 validates it.
  • Download and upload errors say "protwords" for every type.
  • list of an unknown dictionary ID returns an empty list with status 0.
  • Click 8.3 with Typer 0.16 does not enforce required=True on non-repeatable options (also true for existing commands such as tagtype create --owner x, where the server reports the missing name); dict create checks its options itself.

Stacked PRs (merge from the bottom; each PR's base is the branch below it, so no conflicts remain):
main ← #45 theme timeout (+ CI runs for stacked PRs) ← #46 typer ← #43 ops commands ← #44 dict ← #41 general/plugin/storage ← #42 searchlist/documents.
After a PR is squash-merged GitHub retargets the next one to main.

Add fessctl dict list (the dictionary files) and, for each of synonym,
mapping, kuromoji, stopwords, protwords and stemmeroverride, the
subcommands list, get, create, update, delete, upload and download.
The six types share one implementation; each keeps the entry fields of
its admin API form.

update reads the entry first and sends back the unchanged fields.
upload asks for confirmation unless --yes; download writes to standard
output or to --file (not overwritten without --force).

The API exists in 14.19.2, 15.6.1, 15.7.0, 15.8.0 and 15.9.0. Uploads
are POST multipart in 14.x and 15.9; Fess 15.6 to 15.8 only route a
PUT that cannot read a multipart body, so upload is refused there.

list_dict_items takes a dictionary type and ID, so the shared client
paging test now supplies placeholders for required parameters.
@marevol
marevol changed the base branch from main to feat/add-ops-commands October 16, 2026 13:02
@marevol
marevol added this pull request to stack #47 October 16, 2026 13:50
@marevol marevol added this to the 0.4.0 milestone Oct 16, 2026
@marevol marevol self-assigned this Oct 16, 2026
@marevol
marevol merged commit c328330 into main Oct 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant