Simplifying scope in real time index

4 views
Skip to first unread message

Walter Lee Davis

unread,
Mar 16, 2019, 3:30:15 PM3/16/19
to thinkin...@googlegroups.com
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

Pat Allan

unread,
Mar 17, 2019, 12:58:27 AM3/17/19
to thinkin...@googlegroups.com
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
> --
> 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 thinking-sphi...@googlegroups.com.
> To post to this group, send email to thinkin...@googlegroups.com.
> Visit this group at https://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Mar 17, 2019, 10:36:25 AM3/17/19
to thinkin...@googlegroups.com
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
Reply all
Reply to author
Forward
0 new messages