Skip to content

Add admin search for public bodies - #9435

Open
laurentS wants to merge 6 commits into
developfrom
admin-search-public-bodies
Open

Add admin search for public bodies#9435
laurentS wants to merge 6 commits into
developfrom
admin-search-public-bodies

Conversation

@laurentS

@laurentS laurentS commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Relevant issue(s)

Relates to #8814

What does this do?

This sets up a simple UI in /admin/bodies to allow admins to use either the legacy search or the new postgres search engine to find public bodies.

Why was this needed?

We need to test the new search engine on actual data with actual use cases. Making it available on live sites without breaking existing workflows seems like a good way to do this.

Implementation notes

I have included the few tests we had from previous commits to ensure a base level of consistency in results. We need a lot more!

To allow admin search through all the history of edits, I had to add an extra method. Naming improvements welcome :)

Screenshots

Notes to reviewer

With Ma Dada data, searching for mairie (cityhall) leads to 35k+ results under the "exact tag match" section. As there is no pagination on that part of the page, the server has to issue something like 100k db queries to fetch translations+tags, then sends 100+MB to the browser. The client then struggles to render the result. I would suggest we remove the tag based search from this page, and rely on /admin/tags for that purpose, as it handles pagination and all (and we don't actually do partial tag matches anyway, so there is no additional use case handled here).


Have you updated the changelog? If this is not necessary, put square brackets around this: [skip changelog]

@laurentS
laurentS force-pushed the admin-search-public-bodies branch from 125bd81 to ddb1ca4 Compare August 5, 2026 08:26

@garethrees garethrees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review as discussed on our catchup

Comment thread app/models/public_body.rb Outdated
".tag_string": "D"
},
admin_index: {
".searchable_admin_field_versions_as_string": "A",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of all the versions, index the current values for:

request_email: A
last_edit_editor: D
last_edit_comment: D

For past versions we'll make PublicBody::Version itself searchable. We'll need to add a bit more UI to handle that, but we can do that in a separate pull request.

Comment thread app/models/public_body.rb Outdated
".short_name": "A",
"home_page": "B",
".notes_as_string": "C",
".tag_string": "D"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add:

  • disclosure_log: C or D
  • publication_scheme: C or D

Happy if we need to remove tag string as per the PR description

Comment thread app/models/public_body.rb Outdated
".name": "A",
".short_name": "A",
"home_page": "B",
".notes_as_string": "C",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should limit this to only notes on the body directly.

This is meant to be a temporary/test of the new search engine for public
bodies, VS the legacy one.
@laurentS
laurentS force-pushed the admin-search-public-bodies branch from ddb1ca4 to 0f057af Compare August 5, 2026 15:38
@laurentS

laurentS commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Skipping changelog as it won't really provide meaningful info. Might add a line once we've added all models to search

@garethrees

Copy link
Copy Markdown
Member

Skipping changelog as it won't really provide meaningful info. Might add a line once we've added all models to search

Yeah +1

@laurentS

laurentS commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

The tests should be fixed (they pass locally).
I've also added an improvement to prevent N+1 queries when rendering the page. For a full list of 100 authorities, this drops the number of SQL queries from 208 to 11!

@laurentS laurentS changed the title WIP: Add admin search for public bodies Add admin search for public bodies Aug 6, 2026
@laurentS
laurentS marked this pull request as ready for review August 6, 2026 14:27
@laurentS

laurentS commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

Ok, tests finally green. Sorry for the back and forth.

Just as a side note, in the tests, under "stop containers", there is a bunch of FATAL errors and such. It's probably nothing material, given that it's at the very end, but maybe worth a quick check to verify it's nothing that's going to blow up down the line.

The test was incorrectly passing before this PR because PublicBody had
'include Searchable' in its definition, but no call to 'searchable'.
Without the include, there is no search_documents attribute available on
the instance.
@laurentS
laurentS force-pushed the admin-search-public-bodies branch from 4b2aaae to 61deb9f Compare August 7, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants