adamfowleruk wrote: > I recently wanted to come up with a solution to searching by a > category (E.g. Shoes), sub category (E.g. Shoes > Blue), or sub sub > category to any depth. This represents an obvious DB challenge not to > mention model objects in RoR. I've come up with an elegant solution > using Binary Trees and thought it might be useful to others. I've > documented it here: > > http://web.me.com/adamfowleruk/adamslife/Blog/Entries/2009/1/13_A_Strategy_for_Hierarchical_Searches_in_a_single_SQL_entity_table.html > > Note I've not used it in anger yet, and have not QA'ed the Ruby and > Java code at the end of the entry, but the approach is simple enough > and easy for anyone to pick up. > > Category searching to any depth using 1 column/model variable. 8o) > > I'd appreciate any feedback, especially if anyone can think of a more > elegant way to do it?
Adam, the usual way this is done is with the nested-set data structure, which effectively also uses btrees in the DB index for the "left" column. Searching by pattern match would be somewhat slower than such indexed nested-set searches. Your method does have the advantage of being able to add children without having to fix-up the tree afterwards, and for giving each node a permanent hierarchy identifier that makes it easy to do subcategory searches in search-engine indices. The nested-set method can however be tweaked to have the same properties. -- Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---