Hi guys,
Please guide me to execute query.
i have two entity objects "object1", "object2".
both objects has one metadata with different values.
eg: object1->data and object2->data
value of object1->data = "alarm,walk,school,home,sleep";
value of object2->data = "wake up,walk,study,home,play";
i want to get all object2 which has any single value matched with object1->data.
here "walk" and "home" is common value in object1 and object2.
Please give me suggestions to do this.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- enRaiser@enraiser
enRaiser - 0 likes
- Siva Shankar@shankarwram
Siva Shankar - 0 likes
- Matt Beckett@Beck24
Matt Beckett - 0 likes
- Siva Shankar@shankarwram
Siva Shankar - 0 likes
- Matt Beckett@Beck24
Matt Beckett - 1 like
You must log in to post replies.what is type and subtype of object1 and object2 ? I assume its same.
my answer is use LIKE query.
$dbprefix = elgg_get_config("dbprefix");
$options['joins'][] = "JOIN {$dbprefix}metadata prio ON e.guid = prio.entity_guid";
$options['joins'][] = "JOIN {$dbprefix}metastrings prio_name on prio.name_id=prio_name.id";
$options['joins'][] = "JOIN {$dbprefix}metastrings prio_value on prio.value_id=prio_value.id";
$options['wheres'][] = "prio_name.string = 'data'";
$options['wheres'][] = "prio_value.string LIKE '%alarm%' OR prio_value.string LIKE '%walk%' ";
Thanks for your reply enRaiser.
Let me try this.
Instead of storing it like that you should store it like this:
Then you can properly use the options of elgg_get_entities_from_metadata()
Thanks for your help Matt Beckett.
I used this code, but unfortunately its not working.
Instead i used this code for fetching and its working,
And i have one more doubt:
Is my code affect the performance of query execution time when both "object2" entities and $search array increases?
That works too - my code wasn't tested, it should work something like that - maybe it's pluralized 'values'
Anyway, yes, performance will decrease the more search fields you add in. If you're building an app that needs to search on a lot of metadata simultaneously I'd recommend offloading search to solr or something. MySQL doesn't do the best job in that regard