Rapporto Tecnico, Anno 8, n° 45 ottobre 2013 * * Description: reads configuration values and preps a number of key=>value * arrays for output substitution */ function prepFieldSubstitutions() { $rawFacetVals = variable_get("islandora_solr_search_block_facets", 'dc.subject ~ Subject,dc.type ~ Type'); $this->facetFieldArray = islandora_build_substitution_list($rawFacetVals); $rawSearchTerms = variable_get('islandora_solr_searchterms', 'dc.title ~ Title'); $this->searchFieldArray = islandora_build_substitution_list($rawSearchTerms); $rawResultFields = variable_get('islandora_solr_search_result_fields', 'dc.subject ~ Subject,dc.type ~ Type'); $this->resultFieldArray = islandora_build_substitution_list($rawResultFields); $this->allSubsArray = array_merge($this->facetFieldArray, $this->searchFieldArray, $this->resultFieldArray); } /** * Function: displayFacets * * Description: Displays basic facets based on an apache solr query response, * as contained with the IslandoraSolrQueryProcessor. * * @global string $base_url * @param IslandoraSolrQueryProcessor $solrQueryProcessor * @return string */ function displayFacets($solrQueryProcessor) { global $base_url; $output = ''; $islandora_fq = $solrQueryProcessor->solrFilters; $islandora_facets = $solrQueryProcessor->solrResult->facet_counts->facet_fields; if (empty($islandora_facets)) { return $output; //no facets to show } foreach ($islandora_facets as $key => $field) { $list_items = array(); $list_type = "ul"; $list_title = null; $test = get_object_vars($field); //get the number of fields if there aren't any don't show the key if (count($test) > 0) { $facet_count = 0; unset($normal_facet_output); $filter_include = null; $filter_exclude = null; foreach ($field as $name => $number) { if ($islandora_fq && $islandora_fq != '-') //there are existing facets in the query { $disable_link = strstr($islandora_fq, $key . ':"' . replaceSlashes($name) . '"'); //we don't want a link for this facet as we already used it if ($disable_link) { //don't show link to this facet but include a link to remove it } else { $filter_include = $key . ':' . '"' . $name . '"' . IslandoraSolrResults::$facetSeparator . $islandora_fq; $filter_exclude = '-' . $key . ':' . '"' . $name . '"' . IslandoraSolrResults::$facetSeparator . $islandora_fq; } } else //no existing facets chosen { $filter_include = $key . ':' . '"' . $name . '"'; $filter_exclude = '-' . $key . ':' . '"' . $name . '"'; } $filter_include = replaceSlashes($filter_include); //replace the slash so url does not break $filter_exclude = replaceSlashes($filter_exclude); //replace the slash so url does not break if ($disable_link) { // we don't want to create a link, because we're already filtering on this value. // Links to remove enabled facet filters are created down below. } else //normal link { $evenodd = ($facet_count % 2 ? 'odd' : 'even'); $lplus = 'islandora/solr/search/' . $solrQueryProcessor->solrQuery . '/' . $filter_include . '/' . $solrQueryProcessor->solrDefType; $lminus = 'islandora/solr/search/' . $solrQueryProcessor->solrQuery . '/' . $filter_exclude . '/' . $solrQueryProcessor->solrDefType; $text = $name; $attrs = array(); $list_items[] = l($text, $lplus, $attrs) . ' (' . $number . ')' . '<span class="plusminus">' . l('+', $lplus, array( 'attributes' => array( 'class' => 'plus' ) )) . ' ' . l('-', $lminus, array( 'attributes' => array( 'class' => 'minus' ) )) . '</span>'; 77