How to limit search results based only on OG group membership? I followed the tutorial about How to Create Custom Search Pages Using Just Views in Drupal 7.

I have selected the blocks option instead of page option in views as I want to add it as a block in the organic group homepage.

How do I restrict the search using relationship and context filtering in the Views settings so each logged in user can only search for published content of their group only (NOT SITE-WIDE)?

EDIT: I have already tried the following:

Contextual filters > (OG membership from node) OG membership: Group ID
Relationships > OG membership: OG membership from Node

(Which I got the idea from the default og_content view that comes with OG Groups!)

Can this be done with hooks?
Editing my answer here as there seems to be a glitch in Views. Even with no contextual filters or relationships, just filtering by groups audience and exposed search doesn't work. The SQL query has both values but I don't know enough about sql to debug it.


  
  Contextual filters > (OG membership from node) OG membership: Group ID
  Relationships > OG membership: OG membership from Node
  


Instead, here's a hacky way of getting it to work by not using the search module.


Do the same as above to limit results by group.
If you only want to search by title for example, just add an exposed filter for the title and select "contains".
If you want to search by more fields which is likely, add the fields you want to search by (and maybe hide them) eg. Node title / Body. Then create a Global: Combine fields filter (exposed) and select the above fields with "contains".


That will let you search whichever fields but just not as nicely as with the search module.

If anyone else has a solution to the exposed search problem, post please.