MariaDb - NamedQuery to filter records based on a column contains comma-separated values

110 views Asked by At

I have a Spring boot application that connects to a MariaDB to fetch records. In my MariaDb table, I have a column called "tags" and this column consists of comma-separated values something like "summer,vacation,sea,sun,beach,travel".

There is a search form at the frontend. I want to create a NamedQuery to filter the search results.

I have something like this for the "tags" part:

" AND m.tags LIKE CONCAT('%', :tags, '%')"

This is working fine if the user input contains only one word like "summer" or "vacation". It works with multiple words as well but only if you write those words exactly as they appear in the tags column, like "summer,vacation".

The problem occurs when the user types something like: "vacation summer". Since these values are not in order as they persisted in the database, the result becomes an empty list. I receive input value as a list of Strings in the backend.

How can I modify my existing NamedQuery to work with all possible inputs?

0

There are 0 answers