I've got a content type of Journal, and another content type of Article. All of the data associated with the Journal itself is stored on that content type, and not duplicated in the Article; the Article just has an entity reference to the Journal. So, for instance, Journal has a Year field, but Article has no Year field. (Conceptually, a Journal is a collection of Articles.)
For the most part, this entity reference relationship works great (and avoids duplicate information.) However, when doing things like searching, it can have some side effects. For example, if someone searches for a keyword, gets back a list of Articles with that keyword, they're then not able to filter that down by Year using facets, since that content type doesn't technically have a year associated with it, just a reference to a different content type that does. I'm hoping to find a way around that, but I'm not sure how to get it working.
I'm still pretty confused on the relationship between the Solr server we have and the Drupal site. It was my idea that once all was indexed, the Solr server takes the search string, and just ships back nodes/entities/etc. that match. If that's wrong or right, I'm still not sure if my problem has to do with Solr or FacetAPI.
What I've done so far is below, but it seems to have no effect on the search results. (In other words, if I search for a year, the articles aren't being returned as results; I'm not even worrying about Facets yet, even though those are the ultimate goal.)
function issue_archive_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id){
if($node->type == "article") {
// Load the journal this article is associated with, and get it's year
// The is_ prefix is to denote a single (instead of multi-value) integer
$journal = node_load($node->field_journal['und'][0]['target_id']);
$document->setField('is_article_year', intval($journal->field_year['und'][0]['value']));
}
}
function issue_archive_apachesolr_query_prepare(DrupalSolrQueryInterface $query) {
// Make the indexed fields available for search results
$query->addParam('fl', 'is_article_year');
// Filter where 'index_field_name' = 'indexed_value'
$query->addFilter('is_article_year', 'indexed_value');
}