Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
tag browsing (script included) — Gideros Forum

tag browsing (script included)

HolonistHolonist Member
edited May 2015 in General questions
Hi all,

not sure if this fits into code snippets or general questions.

Question-part:

I asked myself how to effectively search for objects with a specific property.

Only thing that came to my mind so far, is to iterate over an array which holds all the objects, then compare the search parameters to the selected field of each object, and return all fitting objects in the end.

I wanted to ask if this is the correct method to do this.
Because it seems really inefficient to me. (If you look at the code it's basically a triple for-loop)

Script-part:
(Including the usage.txt from my project to give you an idea what the the function does)
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.
Feel free to try out the attached demo project and give hints / advice / questions.

Greetings

edit: updated comments in project file
zip
zip
tagTest02.zip
3K

Comments

  • piepie Member
    I am curious about this too, I tried with your approach but it becomes really slow when browsing big tables.

    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

    +1 -1 (+1 / -0 )Share on Facebook
  • right, this looks database style.
    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
  • Just for the record, when I handed 5 million objects to my search function, it took about 15 seconds on my Xeon E3 to print the result number. And afterwards Gideros Player stays at 1GB RAM load. Getting a little crazy over here :D
  • piepie Member
    the solution could be a "propertyHandler" class, which keeps track of variable bindings:
    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 :)
Sign In or Register to comment.