Some sites wish to exclude results from the People directory based on somewhat dynamic criteria (eg, has the searching blocked user blocked one of the users in the result set? Is one of the users suspended on the site via a "suspended" user role)?

Let's document the recommend practice for altering these results.

Comments

ezra-g’s picture

Status: Active » Needs review
StatusFileSize
new896 bytes

Here's what I propose:

The initial list of people presented in the People directory is actually generated by an Entity Field Query, whereas once the user searches, the results are provided by Solr.

So, to alter the results we actually need to alter in 2 places: The EFQ and the Solr query or result set. Here are some suggested approaches for each:

1) EFQ:

Use hook_entity_query_alter() to alter the EFQ that generates the initial People directory listing. The attached patch adds a 'commons_search_solr_user_people' tag to make this query easy to detect.

2) Solr results (see apachesolr.api.php).

A) If you can filter based on content that's included the in Solr index: hook_apachesolr_query_alter().

Eg, for each user that is indexed by Solr, Commons_search_solr_user() adds a property that describes a "list of users who are following this user." See im_flag_commons_follow_user in the commons_search_solr_user.module codebase.

B) If the data on which you're filtering is not included in the index, you can use hook_apachesolr_process_results() to process the returned result set.

japerry’s picture

Status: Needs review » Reviewed & tested by the community

Good idea adding a tag, should make customization easier. now if we could figure out how to not need EFQ for the default search results...

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.