Implement a "Tag search"

Hey guys,

I’m stuck a bit in the moment and hope to find some help.

Goal:
I do have some locations in my database which i wanna search fir based on “tags”. (Like show all Location which are “restaurant” or “bowling centers”)

I thought its a good idea to have a seperate table “Tags” containing all the tags. Then create a Relation Column inside the Location Class to assign all tags.

But i really have no idea how to query correctly for it. Is using arrays containing pointers a better approach?

Help would be great. :slight_smile:

These two solutions should work. I personally prefer to use the relation field instead of an array of pointers. The query on a relation field should be as easy as something like this:

const query = new Parse.Query('Location');
query.equalTo('tags', someTagObject);

Reference: https://docs.parseplatform.org/js/guide/#using-parse-relations

1 Like

But this way we can query only one tag. What if that location is a giant shopping center which include restraunts, cinema and a barber?

I think with this way would be better.
You save location tags as array

JSONArray tags = new JSONArray();
tags.put("barber");
tags.put("cinema");
tags.put("kebap");

Location location = new Location();
location.put("tags",tags);

Then you do query with preferred tags

ParseQuery<Location> getposts = new ParseQuery<Location>(Location.class);
getposts.whereContainsAll("tags",Arrays.asList("barber","cinema","mcdonalds"));

With this method you can get locations with multiple tags with one query.

1 Like

Hey, thanks for your reply!

Seems like a nice solution :slight_smile: - but is it “clever” to save the tags as strings directly in the array? Isn’t it better to save the objectId’s or Pointer Objects ?