What I'm trying to do is get all the "public" pages indexed, and since that starts with the root elements of the tree that are in a particular scope, and then includes the published descendants of each public root, it gets complex from the perspective of ActiveRecord.
The thing that's missing in Ancestry's pre-baked scopes is something along the lines of "this node + all its descendants". Given a node, you can get all its descendants in one go, but then you have to add the parent to the list, and I've never found a pleasing way to do that and end up with a single association. That's why I end up with the sub-select in my example, where I find all the descendant_ids, concatenate the parent id, and the use `where id in (...)` to gather them into a single iterable object. I believe that union operations are coming in a future ActiveRecord, that could make this less long-hand, I suppose. For now, I'll just have to add some comments for "future me" to read. Walter > On Mar 17, 2019, at 12:58 AM, Pat Allan <[email protected]> wrote: > > Hi Walter, > > I can’t think of a better way to do this off the top of my head - I’m > presuming there’s no special scope provided by Ancestry that allows access to > all records (as I understand it, that’s what you’re after?) that can be used > by find_in_batches? > > — > Pat > >> On 17 Mar 2019, at 6:30 am, Walter Lee Davis <[email protected]> wrote: >> >> I've got a combination of TS (latest) and Ancestry in play, and I'm just now >> trying to move from SQL indices to real_time. I was able to make a tortured >> bit of Ruby to collect all the IDs and then return them in a single >> association that TS could find_in_batches over, but I am wondering if there >> is a way to do this that I will not have to stare at so long in a few >> months, when I've forgotten why it works: >> >> scope { Document.where(id: Document.publicly.map{ |d| >> [d.id].concat(d.descendant_ids) }.flatten) } >> >> publicly is a scope that gives me only the "roots" of the ancestry tree with >> a combination of a particular set of slugs and the "published" flag, and >> then I'm appending descendent_ids and making a new collection from the lot >> of them with the outer "find". >> >> Any suggestions? >> >> Thanks in advance, >> >> Walter >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Thinking Sphinx" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/thinking-sphinx. >> For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/thinking-sphinx. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/d/optout.
