diff --git a/IslandoraSolrQueryProcessor.inc b/IslandoraSolrQueryProcessor.inc index 8666810d..392edb3d 100644 --- a/IslandoraSolrQueryProcessor.inc +++ b/IslandoraSolrQueryProcessor.inc @@ -101,11 +101,9 @@ class IslandoraSolrQueryProcessor { $facetArray = array(); $facetFields = ''; - $rawFacetVals = variable_get("islandora_solr_search_block_facets", 'dc.subject,dc.type'); - $facetArray = islandora_build_substitution_list($rawFacetVals); - $facetFields = implode(",", array_keys($facetArray)); + $facetFields = implode(",", variable_get("islandora_solr_search_block_facets", array('dc.subject', 'dc.type'))); $keys = array(''); - $snippetArray = islandora_build_substitution_list(variable_get("islandora_solr_snippet_field", "")); + $snippetArray = variable_get("islandora_solr_snippet_field", ""); if (is_array($snippetArray)) { $keys = array_keys($snippetArray); } @@ -122,7 +120,7 @@ class IslandoraSolrQueryProcessor { 'hl' => 'true', 'hl.fl' => isset($keys[0]) ? trim($keys[0]) : NULL, 'hl.fragsize' => 400, - 'facet.field' => explode(',', $facetFields), //comma separated list configured in the block config + 'facet.field' => array_keys($facetFields), //comma separated list configured in the block config ); diff --git a/IslandoraSolrResults.inc b/IslandoraSolrResults.inc index 6a73c473..1b032bec 100644 --- a/IslandoraSolrResults.inc +++ b/IslandoraSolrResults.inc @@ -18,14 +18,19 @@ class IslandoraSolrResults { public $resultFieldArray = array(); public $allSubsArray = array(); - static function makeArray($in) { - return is_array($in)? + /** + * @deprecated + * This should be factored out in the near future... + */ + static function makeArray(&$in) { + /*return is_array($in)? $in: (isset($in)? array($in): array() ) - ; + ;*/ + return (array)$in; } /** @@ -337,14 +342,17 @@ class IslandoraSolrResults { * 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->facetFieldArray = variable_get("islandora_solr_search_block_facets", array( + 'dc.subject' => 'Subject', + 'dc.type' => 'Type' + )); + $this->searchFieldArray = variable_get('islandora_solr_searchterms', array( + 'dc.title' => 'Title' + )); + $this->resultFieldArray = variable_get('islandora_solr_search_result_fields', array( + 'dc.subject' => 'Subject', + 'dc.type' => 'Type' + )); $this->allSubsArray = array_merge($this->facetFieldArray, $this->searchFieldArray, $this->resultFieldArray); } @@ -362,12 +370,8 @@ class IslandoraSolrResults { $disable_link = (array_search($filter, $fq) !== FALSE) || $number == $solrQueryProcessor->solrResult->response->numFound; - //$disable_link = strpos($islandora_fq, $key . ':"' . . '"') !== FALSE; //we don't want a link for this facet as we already used it if ($islandora_fq && $islandora_fq != '-') {//there are existing facets in the query - if ($disable_link) { - //don't show link to this facet but include a link to remove it - } - else { + if (!$disable_link) { //FIXME: This instance of 't' should be changed to format_string for Drupal 7 (not really translateable) $filter_include = t('!filter!sep!remaining', array( '!filter' => $filter, @@ -384,13 +388,10 @@ class IslandoraSolrResults { $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 - //Doesn't seem to be used... - //$evenodd = ( $facet_count % 2 ? 'odd' : 'even' ); + + if (!$disable_link) {//normal link + //$evenodd = ( $facet_count % 2 ? 'odd' : 'even' ); //Doesn't seem to be used... + $lplus = 'islandora/solr/search/' . $solrQueryProcessor->solrQuery . '/' . $filter_include . '/' . $solrQueryProcessor->solrDefType; $lminus = 'islandora/solr/search/' . $solrQueryProcessor->solrQuery . '/' . $filter_exclude . '/' . $solrQueryProcessor->solrDefType; $text = $name; @@ -430,14 +431,17 @@ class IslandoraSolrResults { if (count($test) > 0) { $primary = array(); $hidden = array(); + $shown_limit = variable_get('islandora_solr_search_block_facet_shown_limit', 5); foreach ($field as $name => $number) { - if (count($primary) < variable_get('islandora_solr_search_block_facet_shown_limit', 5)) { + if (count($primary) < $shown_limit) { $this->_addFacets($key, $name, $number, $solrQueryProcessor, $facet_count, $primary); } else { $this->_addFacets($key, $name, $number, $solrQueryProcessor, $facet_count, $hidden); } } + + if (count($primary) > 0) { $facet_output .='
'; $list_title = $this->facetFieldArray[$key]; @@ -449,10 +453,10 @@ class IslandoraSolrResults { if (count($hidden) > 0) { $list_attributes['class'] = implode(' ', array('islandora_solr_search_facet_list', 'facet_list')); - $facet_output .= "" . t("Show more") . ""; + $facet_output .= "" . t("Show more") . ""; $facet_output .= "
"; - $facet_output .= "" . t("Show less") . ""; + $facet_output .= "" . t("Show less") . ""; $facet_output .= theme_item_list($hidden, '', $list_type, $list_attributes); $facet_output .= "
"; } @@ -536,17 +540,6 @@ EOT; * @return string */ function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) { - $types = array(); - $terms = trim(variable_get('islandora_solr_searchterms', 'dc.title ~ Title,dc.subject ~ Subject')); - $termsArray = preg_split('/[\n]/', $terms); - foreach ($termsArray as $term) { - $vals = split('~', $term); - if (!$vals[1]) { - $vals[1] = $vals[0]; - } - $types[trim($vals[0])] = trim($vals[1]); - } - $queryArray = NULL; if (isset($query)) { //A regex like '\\) (OR|AND) \\(' should work, right? Nope. Seems that @@ -576,7 +569,7 @@ EOT; $repeat = variable_get('islandora_solr_search_block_repeat', '3'); } $i = 1; - $this->_add_field($form, $i, $queryArray[0], $types); + $this->_add_field($form, $i, $queryArray[0], $this->searchFieldArray); if ($repeat > 1 && $repeat < 9) { //don't want less then 2 or more then 9 for ($i = 2; $i < $repeat + 1; $i++) { @@ -591,7 +584,7 @@ EOT; '#default_value' => $andorj, '#options' => $andOrArray ); - $this->_add_field($form, $i, $queryArray[$t], $types); + $this->_add_field($form, $i, $queryArray[$t], $this->searchFieldArray); } } diff --git a/includes/common.inc b/includes/common.inc index 18bb0d38..5a5cb79d 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -121,23 +121,39 @@ function get_search_terms_array($path = NULL, $file = NULL) { } function islandora_build_substitution_list($rawFieldList) { - $facetArray = array(); - $facetFields = ''; + $fieldArray = array(); $lines = preg_split('/[,|\n|\r]/', $rawFieldList); foreach ($lines as $line) { - if( $line ) { + if ($line) { $lineArray = explode('~', $line); - $key = trim($lineArray[0]); - $value = trim($lineArray[1]); - if (!$value) { - $value = $key; + $field = trim($lineArray[0]); + $human_readable_name = trim($lineArray[1]); + if (!$human_readable_name) { + $human_readable_name = $field; } - $facetArray[$key] = $value; - if ($facetFields) { - $facetFields .= ","; - } - $facetFields .= $key; + $fieldArray[$field] = $human_readable_name; } } - return $facetArray; + return $fieldArray; } + +function islandora_stringify_substitutions($subs) { + if (is_array($subs)) { + $parts = array(); + foreach ($subs as $field => $name) { + if ($field !== $name) { + $parts[] = $field .' ~ '. $name; + } + else { + $parts[] = $field; + } + } + + //Implode with a newline... \n doesn't work? + return implode(' +', $parts); + } + else { //This might be gotten rid of in the future, when string versions are extremely unlikely to be encountered (and therefore clobbered) + return $subs; + } +} \ No newline at end of file diff --git a/islandora_solr_config/IslandoraSolrResultsTable.inc b/islandora_solr_config/IslandoraSolrResultsTable.inc index c8e784a6..74f0a0c8 100644 --- a/islandora_solr_config/IslandoraSolrResultsTable.inc +++ b/islandora_solr_config/IslandoraSolrResultsTable.inc @@ -113,7 +113,7 @@ class IslandoraSolrResultsTable extends IslandoraSolrResults { unset($rowclass); $result_num = $recordStart + $num + 1; $rows[$row][] = array( - 'data' => (isset($val_array['PID']) ? l($result_num,'fedora/repository/'.$val_array['PID']) : $result_num), + 'data' => (isset($val_array['PID']) ? l($result_num,'fedora/repository/'. $val_array['PID']) : $result_num), 'header' => TRUE, ); foreach ($fields as $field) { @@ -131,7 +131,7 @@ class IslandoraSolrResultsTable extends IslandoraSolrResults { if( variable_get('islandora_solr_search_debug_mode', 0) ) { // debug dump $results_r .= "
Results: ".print_r($results,TRUE)."
"; $fieldset_r = array( - '#title' => t("Raw Results"), + '#title' => t("Raw Results"), '#collapsible' => TRUE, '#collapsed' => TRUE, '#value' => $results_r, diff --git a/islandora_solr_search.admin.inc b/islandora_solr_search.admin.inc index 55433a97..03556576 100644 --- a/islandora_solr_search.admin.inc +++ b/islandora_solr_search.admin.inc @@ -143,26 +143,26 @@ function islandora_solr_admin_settings(&$form_state) { Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie dc.title ~ Title
Review the schema.xml to see what terms are available. A list of the fields available when using the schema.xml packaged with the Islandora Solr module is available in Islandora's online documentation."), - '#default_value' => variable_get('islandora_solr_searchterms', 'dc.title ~ Title'), + '#default_value' => islandora_stringify_substitutions(variable_get('islandora_solr_searchterms', array('dc.title' => 'Title'))), '#wysiwyg' => FALSE, ); $form['islandora_solr_snippet_field'] = array( '#type' => 'textfield', '#title' => t('Snippet Field'), - '#default_value' => variable_get('islandora_solr_snippet_field', ''), + '#default_value' => islandora_stringify_substitutions(variable_get('islandora_solr_snippet_field', array())), '#description' => t("If a match is found on this field, a snippet of text will be returned, with the search term highlighted.
An optional friendly label may inserted using the following pattern dsm.Text ~ Full Text
Note: This feature is not supported by all display profiles. "), '#wysiwyg' => FALSE, ); + $form['islandora_solr_search_block_facets'] = array( '#type' => 'textarea', '#title' => t('Facet Fields'), '#description' => t("Indicate which fields will appear in the Islandora Facet Block.
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie dc.title ~ Title "), - '#default_value' => variable_get('islandora_solr_search_block_facets', 'dc.subject ~ Subject,dc.type ~ Type'), + '#default_value' => islandora_stringify_substitutions(variable_get('islandora_solr_search_block_facets', array('dc.subject' => 'Subject', 'dc.type' => 'Type'))), '#wysiwyg' => FALSE, - '#default_value' => variable_get('islandora_solr_search_block_facets', t('dc.subject ~ Subject,dc.type ~ Type')) ); $form['islandora_solr_search_result_fields'] = array( @@ -170,7 +170,7 @@ function islandora_solr_admin_settings(&$form_state) { '#title' => t('Labels for Returned Fields'), '#description' => t('Set labels for fields returned from query. Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie dc.title ~ Title'), - '#default_value' => variable_get('islandora_solr_search_result_fields', 'dc.subject ~ Subject,dc.type ~ Type'), + '#default_value' => islandora_stringify_substitutions(variable_get('islandora_solr_search_result_fields', array('dc.subject' => 'Subject', 'dc.type' => 'Type'))), '#wysiwyg' => FALSE, ); @@ -349,6 +349,14 @@ function solr_settings_form_submit($form, &$form_state) { // Exclude unnecessary elements. unset($form_state['values']['submit'], $form_state['values']['reset'], $form_state['values']['form_id'], $form_state['values']['op'], $form_state['values']['form_token'], $form_state['values']['form_build_id']); + $toBlowUp = array( + 'islandora_solr_search_result_fields', + 'islandora_solr_search_block_facets', + 'islandora_solr_searchterms', + 'islandora_solr_search_sort', + "islandora_solr_snippet_field" + ); + foreach ($form_state['values'] as $key => $value) { if ($op == t('Reset to defaults')) { variable_del($key); @@ -357,6 +365,9 @@ function solr_settings_form_submit($form, &$form_state) { if (is_array($value) && isset($form_state['values']['array_filter'])) { $value = array_keys(array_filter($value)); } + elseif (array_search($key, $toBlowUp) !== FALSE) { + $value = islandora_build_substitution_list($value); + } variable_set($key, $value); } } @@ -367,6 +378,7 @@ function solr_settings_form_submit($form, &$form_state) { drupal_set_message(t('The solr configuration options have been saved.')); } + //This cache clearing and rebuilding really necessary? -avessey cache_clear_all(); drupal_rebuild_theme_registry(); } diff --git a/islandora_solr_search.css b/islandora_solr_search.css index c726d96a..63dcb811 100644 --- a/islandora_solr_search.css +++ b/islandora_solr_search.css @@ -31,6 +31,7 @@ form#islandora-solr-simple-search-form input#edit-islandora-simple-search-query { font-size:90%; line-height:1.3em; + clear: both; } img.islandora_solr_add_remove_link diff --git a/islandora_solr_search.module b/islandora_solr_search.module index dd2ac3a0..ac26f7ac 100644 --- a/islandora_solr_search.module +++ b/islandora_solr_search.module @@ -290,7 +290,7 @@ function theme_islandora_solr_search_block_form($form) { * @param type $dismax * @return type */ -function islandora_solr_search($query, $fq=NULL, $dismax=NULL) { +function islandora_solr_search($query='', $fq=NULL, $dismax=NULL) { global $queryClass; islandora_solr_search_init();