We have a use case where users must be able to search content that is only available in Groups that they have access to. The search must be across all groups that they have access to.
Some details: A Group has many Posts, and a user may have access to hundreds of Groups and thousands of Posts within each Group. A search for "Foo" should return all Groups with "Foo" in the name and all Posts, within the Groups that they have access to, and have "Foo" in the content.
The way I thought of dealing with it is to have a list of user_id's associated on each document index and then include the user_id in the query string to verify that the user has access. Once the results are returned we could do an additional check to see that they have access to the content before returning the results.
The document index is something like this:
fields = [
search.TextField(name="data", value="some searchable stuff"),
search.AtomField(name="post_id", value="id of post"),
search.AtomField(name="group_id", value="id of group"),
search.AtomField(name="user_id", value=user_id_1),
search.AtomField(name="user_id", value=user_id_2),
#.... add the thousand other users who have access to the group (done in loop)
]
#then query run a user 123 would be as follows:
results = index.search("data = Foo AND user_id = 123")
My concern with the above approach: Every new user who subscribes to a group would require the search index to be reindexed to include their user_id on each document.
Is there a better way of handling this use case?
Thanks Rob