Skip to content

Conversation

Copy link

Copilot AI commented Nov 28, 2025

Issue requested replacing LIKE with strict_word_similarity() for fuzzy search. Rather than a hard switch, this implements an opt-in approach preserving backward compatibility while enabling trigram-based fuzzy matching when desired.

Changes

  • Configuration (conf/mapbender.conf-dist):

    • SEARCH_USE_TRIGRAM (default: false) — toggle fuzzy search
    • SEARCH_TRIGRAM_THRESHOLD (default: 0.3) — similarity threshold (0.0-1.0)
  • Search logic (http/classes/class_metadata.php):

    • When enabled: uses word_similarity($param, searchtext) > threshold
    • When disabled: unchanged LIKE behavior
    • Threshold validated and clamped to valid range

Usage

// In mapbender.conf (requires: CREATE EXTENSION pg_trgm;)
define("SEARCH_USE_TRIGRAM", true);
define("SEARCH_TRIGRAM_THRESHOLD", 0.3);

Default behavior unchanged — existing installations unaffected.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fuzzy search with trigram</issue_title>
<issue_description>Issue copied from:
mrmap-community#55

For the fuzzy search, there are some algorithm like levenshtein, soundex, word_similarity and so on.

https://www.postgresql.org/docs/current/fuzzystrmatch.html
https://www.postgresql.org/docs/current/pgtrgm.html

In the mapbender/http/classes/class_metadata.php in line 1284, the code could be change from:
$whereStr .= "searchtext LIKE $" . ($i + 1);
to
$whereStr .= "(strict_word_similarity($" . ($i + 1) . ", searchtext) > 0.2)";

In order to use strict_word_similarity( ) function, we need to install in the postgres first.
CREATE EXTENSION pg_trgm;

Work still need to be done: Check the performance of the search, since a new algorithm is used instead of LIKE.</issue_description>

<agent_instructions>Do you have a better way to solve the problem and it should be fast too.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@dpakprajul I think its better to close this issue as it won't go further and has no future. Okay?

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 28, 2025 09:51
Co-authored-by: dpakprajul <38970123+dpakprajul@users.noreply.github.com>
Co-authored-by: dpakprajul <38970123+dpakprajul@users.noreply.github.com>
Copilot AI changed the title [WIP] Add fuzzy search with trigram support Add optional fuzzy search using PostgreSQL pg_trgm extension Nov 28, 2025
Copilot AI requested a review from dpakprajul November 28, 2025 09:55
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.

Fuzzy search with trigram

2 participants