nostpy-relay icon indicating copy to clipboard operation
nostpy-relay copied to clipboard

`search` uses case sensitive query

Open gasaichandesu opened this issue 9 months ago • 1 comments

Hey, here is another issue we are facing. We have a search functionality in our Nostr client where we allow to enter an arbitrary search term which is then used in a search field inside of filters.

However this search is not reliable and I found out why. It is because SQL query which is built for search terms is case sensitive. Thus some events are often missing.

Is it the intended behavior? Or more like a bug? I would prefer search always being case insensitive

gasaichandesu avatar Mar 26 '25 21:03 gasaichandesu

Thanks for opening this issue! That explains why I wasn’t able to reproduce the problem.

This was an oversight on my part rather than an intentional decision, so I’ll label it as a bug. I think the best workaround for now is to use the ILIKE operator instead of LIKE.

For example, updating this:

def _search_clause(self, search_item):
    search_clause = f" EXISTS ( SELECT 1 FROM jsonb_array_elements(tags) as elem WHERE elem::text LIKE '%{search_item}%' OR content LIKE '%{search_item}%')"
    return search_clause

to this:

def _search_clause(self, search_item):
    search_clause = (
        f" EXISTS ("
        f" SELECT 1 FROM jsonb_array_elements(tags) AS elem"
        f" WHERE elem::text ILIKE '%{search_item}%'"
        f" OR content ILIKE '%{search_item}%')"
    )
    return search_clause

I'll test this out and link the branch to this issue for further testing.

UTXOnly avatar Mar 29 '25 14:03 UTXOnly