rajo Posted November 19, 2014 Posted November 19, 2014 Hi all, I'm wondering what the faster, most scalable, way to populate a search criterion <select> control would be, in a case as follows: Let's say there's a list of colour pages: red, blue, etc... They are referenced as thing->colours in the thing template, in a multi-value Page field. It's possible not all colours are actually assigned to things (e.g. maybe no thing has green in its colours field). Now, in the search form, if I build a <select> as follows, I'll end up w/ "green", which invites empty search results -- teasing the user... foreach($pages->find("template=colour,sort=sort") as $item) { ... } Here's my current solution. I'm wondering whether it'll scale and perform. In the following code, I exclude MarkupCache to keep the logic clearer: $things = $pages->find('template=thing'); $ids = implode( '|', array_unique( explode( '|', $things->implode('|', 'colours')), SORT_NUMERIC)); foreach($pages->find("id={$ids},sort=sort") as $item) { ... } $things could be a rather large PageArray. Is PageArray->implode() efficient? Is array_unique efficient? Yes, I could do measurements, but I was wondering whether this common problem already had been given some thought? Bueller? Many thanks. Jean
LostKobrakai Posted November 20, 2014 Posted November 20, 2014 foreach($pages->find("template=colour,sort=sort") as $item) { if($pages->get("template=thing, colour=$item")->id){ //There are actually pages with this colour } } Regarding your performance question: Loading one page per color should be nicer than loading all $thing pages. Even without all your sorting stuff. 1
rajo Posted November 20, 2014 Author Posted November 20, 2014 @LostKobrakai, thanks for your reply. I see what you're saying. I'll go in that direction. There aren't as many colours as there are things, of course.
Recommended Posts