Using tagify to find all fields that contains any tag?

I’m trying to use a tagify element to find all entries in the database where a field contains any of the tagify input tags, but can’t figure out how to do it.

The query is Field_name in {{$_GET.tags}} The get parameter is populated by the tagify element. But it will only work with one tag, when a second tag is added it no longer returns any result.

What I’m hoping to achieve is to find “all users where the user’s field contains any of the tagify tags”

e.g.
Field is “favourite_colour” and User A has “red”, and User B has “blue”.
Another user searches for users with favourite colours of either red or blue in the favourite field.
I want it to return both users.

Perhaps someone has already used tagify in this manner and can point me in the right direction? :pray:

Try Field_Name in {{$_GET.tags.split(',')}}

Thank you @bpj, unfortunately that does not solve the issue. The behaviour is the same, it will only return a result for the first tag.

It will find everyone whose field says “blue” and when “red” is added as a second tag, it finds no results at all. I thought maybe it’s not looking at individual fields, but for a comma separated field with “blue, red” so I tried creating a field for one user that says “blue, red” but it didn’t find that either.

Bumping this, as I can not for the life of me figure out what I’m doing wrong.

I’ve created a new test query in case it was something wrong with my actual query, as it’s fairly complex.

So this is my new test query.

Running in the browser; http://localhost:3000/api/talent/test?skills=pink

Returns
Screenshot 2023-06-05 at 10.47.01 PM

Running in the browser; http://localhost:3000/api/talent/test?skills=blue

Returns
Screenshot 2023-06-05 at 10.48.17 PM

Running in the browser; http://localhost:3000/api/talent/test?skills=pink,blue

Returns (nothing)
Screenshot 2023-06-05 at 10.49.32 PM

I’ve tried every possible combination of things that I can think of. like splitting the string in the query. setting the param to an array. converting text to string and then splitting string… I’m just throwing stuff at it at this point to see if anything works.

Using “in” as opposed to “contains” returns a 500 status, no idea what to make of that.

If I still had any hair left I would be pulling it out by now!

It’s a nodeJS project using a sqlite db.

How exactly are you storing these values in the database?

@Teodor

As a text field with the values comma separated as such “pink,green,blue”. I’ve also tried it as a string field, but I understand nodeJS doesn’t care if it’s text or string type?

Being an old Bubbler, you had to define a field to be a “list” for this type of operation. But I wasn’t able to find a way of defining the field type as a list equivalent. e.g. an array type.

And the behaviour seems to be that it doesn’t understand it’s individual values, but a, you know, text. and finds the single word “blue” and “pink,blue” as a word of course doesn’t exist, so it won’t find anything.

That’s why I also tried the separate operation “,” in the query builder.

I’m sure I’m doing something very obviously wrong here, but I can’t figure out what I’m doing wrong.
But being a bit bubble damaged™ ©2023, I’m most likely thinking about it backwards.

That is a bad practice. You should not store values like that.
You need a table for your users and another table for the colors, related by the userid.
The other option is to use a json field type to store the values in the database, as explained here: Inserting Tagify Values into a Database

1 Like

Right, so I tried that as well. that was the original issue of the thread. I had the same result, which lead me to believe that perhaps it had to be a comma separated field

So here’s the original example set up. not a subtable of skills, since I couldn’t figure out how to search a sub table, that will be an upcoming thread :wink:

I have three users, each has a field “skills”.

Screenshot 2023-06-06 at 9.06.33 AM

Query: http://localhost:3000/api/talent/test?skills=pink
Returns:
Screenshot 2023-06-06 at 9.08.47 AM

But again,

Query: http://localhost:3000/api/talent/test?skills=pink,blue
Returns: (nothing)
Screenshot 2023-06-06 at 9.09.50 AM

And the condition looks like this, I tried both split and no split.

You need to use IN (not contains) when using an array to filter the query.

1 Like

how on earth… it works!! I was so sure I had tried that combination, especially after @bpj suggested split.
Time to backtrack and figure out what I did wrong before.

Thank you so much @Teodor this was doing my head in for the better part of yesterday.

1 Like

Note that IN won’t work when storing the values as a comma separated string like blue, purple, green in a single database field.