Here is one way to build a custom search component that automatically selects facets based on the results:
1. Create a class that extends SearchComponent and implements the prepare and process methods.
2. In prepare, analyze the query and use Lucene's term vectors or other analysis to determine which fields are likely to provide useful facets. Add these fields to the response builder.
3. In process, after the normal query processing, generate facet counts for the fields added in prepare. Add the facet counts to the response.
4. Register the component in solrconfig.xml and configure it to run after the query and facet components.
Now facets will be automatically selected without needing to specify them in the request.