It looks like you're new here. If you want to get involved, click one of these buttons!
usage: results = searchX(objects, field, params) returns: a table of objects (which is a subset <= objects) explanation: objects (table) = the table of objects you want to browse field (string) = the field you want to check params (table) = the values which you're looking for in object.field example1: results = searchX(apples, "id", {2}) -> results will contain all apples who have: self.id=2 example2: results = searchX(myObjectList, "tags", {"funny", "nice", "red"}) -> results will contain all myObjects with self.tags = {"funny", "nice", "red", ...} -> multiple params are AND-ed, so passing multiple search terms will always NARROW DOWN the search. |
Comments
I worked that around keeping track of tags in other tables referencing the objects id, but it could be harder to set up and maintain, and you end up with smaller tables (easy to browse) but much many in number.
If you manage to keep it clean though, you don't even need to browse a table as long as you know the id of the object you're searching for, just ask if color.yellow[appleID] exists, while pairs(color.yellow) would give you every yellow appleID.
something like
apples = {1 = {...}, 2 = {...} ....}
color.yellow = {1,3}
color.green = {4,6}
hope this helps
Likes: Holonist
so instead of saying apple.color = "yellow" we store the apple id in the color table.
Interesting, but I don't trust my variable-binding skills enough yet to try something like this. Looks like it could go terribly wrong if you forget to update ALL tables where your objects have their fingers in
it was something I would have done, but at the time I was not able to do it, and now I am already settled and I don't want to risk breaking everything