Skip to content

BDMS-764: Add contact name & type to water well list search#667

Open
TylerAdamMartinez wants to merge 11 commits intostagingfrom
TAM-BDMS-764
Open

BDMS-764: Add contact name & type to water well list search#667
TylerAdamMartinez wants to merge 11 commits intostagingfrom
TAM-BDMS-764

Conversation

@TylerAdamMartinez
Copy link
Copy Markdown
Contributor

@TylerAdamMartinez TylerAdamMartinez commented Apr 30, 2026

Why

This PR addresses the following problem/context:

  • Search functionality was limited to name_contains, restricting users to exact/partial name matches only
  • Users could not effectively search by other attributes, such as thing type or related contact names
  • The existing search did not handle typos or approximate matches (e.g., “Aron” vs “Aaron”)
  • This limited usability and made it difficult to locate relevant records

How

Implementation summary - the following was changed/added/removed:

  • Replaced name_contains parameter with a unified query parameter across the frontend and backend
  • Implemented a combined search strategy in get_db_things():
    • Full-text search using Thing.search_vector (tsvector)
    • Fuzzy matching using PostgreSQL pg_trgm (% operator)
    • Added similarity-based ranking using similarity() to improve result ordering

Notes

Any special considerations, workarounds, or follow-up work to note?

  • Requires PostgreSQL pg_trgm extension to be enabled for fuzzy search
  • Search behavior now depends on both search_vector configuration and trigram matching
  • Contact search is only applied when include_contacts=true to avoid unnecessary joins

@TylerAdamMartinez TylerAdamMartinez changed the title BDMS-764: Add contact name & type to water well list BDMS-764: Add contact name & type to water well list search Apr 30, 2026
@TylerAdamMartinez TylerAdamMartinez self-assigned this May 1, 2026
@TylerAdamMartinez TylerAdamMartinez added bug Something isn't working enhancement New feature or request labels May 1, 2026
@TylerAdamMartinez TylerAdamMartinez marked this pull request as ready for review May 1, 2026 16:45
Copy link
Copy Markdown
Contributor

@jacob-a-brown jacob-a-brown left a comment

Choose a reason for hiding this comment

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

Should the query be sanitized to prevent malicious behavior?

@TylerAdamMartinez
Copy link
Copy Markdown
Contributor Author

TylerAdamMartinez commented May 1, 2026

Should the query be sanitized to prevent malicious behavior?

Yes, good point. I double-checked that there is nowhere in this code change where a user query parameter is placed directly into an SQL statement.

@TylerAdamMartinez
Copy link
Copy Markdown
Contributor Author

Grabacion.de.pantalla.2026-05-04.a.la.s.13.24.30.mov

@ksmuczynski
Copy link
Copy Markdown
Contributor

Are these changes carried over into the Docker setup, too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants