I would like to know If there are any ways to go about searching for a keyword in a DataStore. I’m working with user generated content and naturally I have to implement a search feature.
The DataStore follows a format like this:
["creation_id"] = {
name = "creation_name",
description = "keywords",
}
However I can’t think of any possible ways to implement such feature. Calling :ListKeysAsync() and iterating through each creation getting their data with :GetAsync is too costy and will hit a requests cooldown.
I don’t believe that Roblox datastores are designed for this so doing it efficiently is somewhat difficult, but there are some ways you could achieve your goals.
1. Use an External Server to Handle Retrieval (recommended)
In my opinion, the best way to achieve your goal is to use an external server which can handle all the data saving and searching. You get many more features when creating your own server to handle data and there are a lot of tools designed to do this. Although I understand this may not be an option for you or you just don’t want to do this.
2. Save the Post’s Id for Each Keyword
Whenever someone creates a post, it takes each keyword and adds it’s id to a list of posts containing this keyword. It’s kind of hard to explain with words but I would just do it like this
When someone creates a search, you take each word and do a Get request from the DataStore, then you get all the posts that have that keyword in it. For example, if you search for KeyWord1 it will return Post1Id and Post2Id.
I understand that this isn’t exactly an amazing idea, but with Roblox’s limitations it’s about the best you can do without getting extremely complex. Hope this helped at least a little.