diff --git a/SolrSearchPlugin.php b/SolrSearchPlugin.php index 148839ea..9c8c387c 100644 --- a/SolrSearchPlugin.php +++ b/SolrSearchPlugin.php @@ -224,15 +224,15 @@ protected function _addFacetMappings() $elements = $this->_db->getTable('Element')->findAll(); $sql = <<_db->prefix}solr_search_facets` - (element_id, name, element_set_id, is_facet, is_displayed, is_sortable) - VALUES (?, ?, ?, ?, ?, ?); + (element_id, name, element_set_id, is_facet, is_displayed) + VALUES (?, ?, ?, ?, ?); SQL; $stmt = $this->_db->prepare($sql); - // $stmt->execute(array(null, 'Image', null, 1, 1, 1)); - $stmt->execute(array(null, 'Tag', null, 1, 1, 1)); - $stmt->execute(array(null, 'Collection', null, 1, 1, 1)); - $stmt->execute(array(null, 'Itemtype', null, 1, 1, 1)); + // $stmt->execute(array(null, 'Image', null, 1, 1)); + $stmt->execute(array(null, 'Tag', null, 1, 1)); + $stmt->execute(array(null, 'Collection', null, 1, 1)); + $stmt->execute(array(null, 'Itemtype', null, 1, 1)); foreach ($elements as $element) { $v = 0; @@ -244,8 +244,7 @@ protected function _addFacetMappings() } $stmt->execute(array( - $element['id'], $element['name'], $element['element_set_id'], - $v, $v, $v + $element['id'], $element['name'], $element['element_set_id'], 0, $v )); } } @@ -287,7 +286,6 @@ protected function _createSolrTable() `element_set_id` int(10) unsigned, `is_facet` tinyint unsigned DEFAULT 0, `is_displayed` tinyint unsigned DEFAULT 0, - `is_sortable` tinyint unsigned DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; SQL; diff --git a/controllers/ConfigController.php b/controllers/ConfigController.php index 84ebb408..d488389c 100644 --- a/controllers/ConfigController.php +++ b/controllers/ConfigController.php @@ -55,7 +55,7 @@ public function indexAction() $options = array(); /** - * Test for is_facet and is_sortable values. + * Test for is_facet values. */ // is_displayed @@ -72,18 +72,10 @@ public function indexAction() $options['is_facet'] = 0; } - // is_sortable - if (isset($values) && in_array('is_sortable',$values)){ - $options['is_sortable'] = 1; - } else { - $options['is_sortable'] = 0; - } - $data = array( 'id' => $split[1], 'is_displayed' => $options['is_displayed'], - 'is_facet' => $options['is_facet'], - 'is_sortable' => $options['is_sortable'] + 'is_facet' => $options['is_facet'] ); try { diff --git a/controllers/ResultsController.php b/controllers/ResultsController.php index cdda0afd..c65f5865 100644 --- a/controllers/ResultsController.php +++ b/controllers/ResultsController.php @@ -108,8 +108,6 @@ private function getSearchParameters($facets) { $fields .= ",$hiddenFields"; } - $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ''; - if (!empty($facets)) { $params = array( 'fl' => $fields, @@ -120,13 +118,11 @@ private function getSearchParameters($facets) { 'hl' => get_option('solr_search_hl'), 'hl.snippets' => get_option('solr_search_snippets'), 'hl.fragsize' => get_option('solr_search_fragsize'), - 'sort' => $sort, 'facet.sort' => get_option('solr_search_facet_sort') ); } else { $params = array( - 'fl' => $displayFields, - 'sort' => $sort + 'fl' => $displayFields ); } diff --git a/forms/FacetForm.php b/forms/FacetForm.php index 9802593e..36fc4b8a 100644 --- a/forms/FacetForm.php +++ b/forms/FacetForm.php @@ -59,7 +59,7 @@ public function init() // Construct values array. $values = array(); - foreach (array('is_displayed', 'is_facet', 'is_sortable') as $key) { + foreach (array('is_displayed', 'is_facet') as $key) { if ($facet->$key == 1) { array_push($values, $key); } @@ -70,8 +70,7 @@ public function init() 'label' => $facet->name, 'multiOptions' => array( 'is_displayed' => 'Is Searchable', - 'is_facet' => 'Is Facet', - 'is_sortable' => 'Is Sortable' + 'is_facet' => 'Is Facet' ), 'value' => $values )); diff --git a/helpers/SolrSearch_IndexHelpers.php b/helpers/SolrSearch_IndexHelpers.php index 4ae42b13..1c5a92fe 100644 --- a/helpers/SolrSearch_IndexHelpers.php +++ b/helpers/SolrSearch_IndexHelpers.php @@ -118,7 +118,7 @@ public static function getIndexSet($db) ->findAll(); foreach ($facets as $facet) { - if ($facet->is_displayed || $facet->is_facet || $facet->is_sortable) { + if ($facet->is_displayed || $facet->is_facet) { $key = $facet->element_id ? $facet->element_id : strtolower($facet->name); diff --git a/helpers/SolrSearch_ViewHelpers.php b/helpers/SolrSearch_ViewHelpers.php index 0b84a90d..f89e7e64 100644 --- a/helpers/SolrSearch_ViewHelpers.php +++ b/helpers/SolrSearch_ViewHelpers.php @@ -158,107 +158,6 @@ public static function getDocTitle($doc) return $title; } - /** - * - * @return Zend_Form - */ - function createSortForm() - { - $params = SolrSearch_QueryHelpers::getParams(); - $uri = SolrSearch_ViewHelpers::getBaseUrl(); - require "Zend/Form/Element.php"; - - $form = new Zend_Form(); - $form->setAction($uri); - $form->setMethod('get'); - $form->setDecorators(array('FormElements',array('HtmlTag', array('tag' => 'div')),'Form',)); - - $query = new Zend_Form_Element_Hidden('solrq'); - $query->setValue($params['q']); - $query->setDecorators( - array('ViewHelper', - array(array('data' => 'HtmlTag'), - array('tag' => 'span', 'class' => 'element')), - array('Label', array('tag' => 'span')),)); - $form->addElement($query); - - $facet = new Zend_Form_Element_Hidden('solrfacet'); - $facet->setValue($params['facet']); - $facet->setDecorators( - array('ViewHelper', - array(array('data' => 'HtmlTag'), - array('tag' => 'span', 'class' => 'element')), - array('Label', array('tag' => 'span')),)); - $form->addElement($facet); - - $sortField = new Zend_Form_Element_Select('sort'); - $sortField->setLabel('Sorted By:'); - - //get sortable fields - $db = get_db(); - $sortableList = $db - ->getTable('SolrSearch_Facet') - ->findBySql('is_sortable = ?', array('1')); - - //sortable fields - $fields = array(); - $fields[''] = 'Relevancy'; - foreach ($sortableList as $sortable) { - if ($sortable->element_id != NULL) { - $elements = $db - ->getTable('Element') - ->findBySql( - 'element_set_id = ?', - array($sortable['element_set_id']) - ); - - foreach ($elements as $element) { - if ($element['name'] == $sortable['name']){ - $fields[$element->id . '_s asc'] = $element->name - . ', Ascending'; - $fields[$element->id . '_s desc'] = $element->name - . ', Descending'; - } - } - } else { - $fields[$sortable->name . ' asc'] = ucwords($sortable->name) - . ', Ascending'; - $fields[$sortable->name . ' desc'] = ucwords($sortable->name) - . ', Descending'; - } - } - - $sortField->setOptions(array('multiOptions'=>$fields)); - $sortField->setDecorators(array('ViewHelper', - array( - array('data' => 'HtmlTag'), - array('tag' => 'span', 'class' => 'element')), - array('Label', array('tag' => 'span')),)); - - //select the current sorted option - $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : ''; - $sortField->setValue($sort); - $form->addElement($sortField); - - //Submit button - $form->addElement('submit','submit'); - $submitElement=$form->getElement('submit'); - $submitElement->setLabel('Go'); - $submitElement->setDecorators(array( - 'ViewHelper', array( - array('data' => 'HtmlTag'), - array('tag' => 'span', 'class' => 'element')),)); - - - // Only return the form if there are sortable fields (other than - // relevancy). - if (count($fields) > 1) { - return $form; - } else { - return ''; - } - } - /** * Return the path for an image * @@ -346,17 +245,20 @@ public static function tagsToStrings($tags=array(), $delimiter=null) if(!empty($tags)) { $tagStrings = array(); - foreach($tags as $key => $tag) { - $label = html_escape($tag); - - if(isset($current['facet'])) { - $facetq = $current['facet'] . '+AND+tag:"' . $label .'"'; - } else { - $facetq = 'tag:"' . $label .'"'; + if (is_array($tags)) { + foreach($tags as $key => $tag) { + $tagStrings[$key] = SolrSearch_ViewHelpers::tagToString( + $uri, $current, $tag + ); } - $searchpath = $uri . '?sorlq=' . $current['q'] . '&solrfacet=' . htmlspecialchars($facetq, ENT_QUOTES); - $tagStrings[$key] = '' . $label . ''; + } else { + $parts = explode(',', $tags); + foreach ($parts as $tag) { + $tagStrings[$tag] = SolrSearch_ViewHelpers::tagToString( + $uri, $current, trim($tag) + ); + } } $tagString = join(html_escape($delimiter), $tagStrings); @@ -365,6 +267,33 @@ public static function tagsToStrings($tags=array(), $delimiter=null) return $tagString; } + /** + * This takes atag and returns a string containing the tab label wrapped in + * an A. + * + * @param string $uri The base URI for the links + * @param array $params The current set of search parameters. + * @param string $tag The tag to change to a wrapped string. + * + * @return string $a The A tag. + * @author Eric Rochester + **/ + private static function tagToString($uri, $params, $tag) + { + $label = html_escape($tag); + + if (isset($params['facet'])) { + $facetq = $params['facet'] . '+AND+tag:"' . $label .'"'; + } else { + $facetq = 'tag:"' . $label .'"'; + } + + $searchpath = $uri . '?sorlq=' . $params['q'] . '&solrfacet=' . htmlspecialchars($facetq, ENT_QUOTES); + $a = '' . $label . ''; + + return $a; + } + /** * This creates and returns the configuration form. * @@ -409,7 +338,7 @@ public static function makeConfigFields($form=null) { ->addErrorMessage('Results count must be numeric'); $fields[] = SolrSearch_ViewHelpers::makeOptionField( - $form, 'solr_search_facet_sort', 'Default Sort Order:', false, + $form, 'solr_search_facet_sort', 'Facet Field Constraint Order:', false, null, 'Zend_Form_Element_Select' ) ->addMultiOption('index', 'Alphabetical') diff --git a/models/SolrSearchFacet.php b/models/SolrSearchFacet.php index 8fbff26a..b732a4e4 100644 --- a/models/SolrSearchFacet.php +++ b/models/SolrSearchFacet.php @@ -51,11 +51,6 @@ class SolrSearchFacet extends Omeka_Record */ public $is_displayed; - /** - * Sortable status [boolean/tinyint]. - */ - public $is_sortable; - /** * Get the parent element set. diff --git a/tests/unit/SolrSearchFacetTest.php b/tests/unit/SolrSearchFacetTest.php index e0cecc3c..ad4d4cbd 100644 --- a/tests/unit/SolrSearchFacetTest.php +++ b/tests/unit/SolrSearchFacetTest.php @@ -42,7 +42,6 @@ public function testAttributeAccess() $facet->name = 'name'; $facet->is_facet = 1; $facet->is_displayed = 1; - $facet->is_sortable = 1; $facet->save(); // Re-get the facet object. @@ -54,7 +53,6 @@ public function testAttributeAccess() $this->assertEquals($facet->name, 'name'); $this->assertEquals($facet->is_facet, 1); $this->assertEquals($facet->is_displayed, 1); - $this->assertEquals($facet->is_sortable, 1); } diff --git a/views/admin/config/index.php b/views/admin/config/index.php index 9b613a50..5b84cb57 100644 --- a/views/admin/config/index.php +++ b/views/admin/config/index.php @@ -38,8 +38,7 @@ null, 'Is Searchable' => null, - 'Is Facet' => null, - 'Is Sortable' => null + 'Is Facet' => null )); ?> diff --git a/views/shared/results/index.php b/views/shared/results/index.php index 79034719..bde878ab 100644 --- a/views/shared/results/index.php +++ b/views/shared/results/index.php @@ -25,8 +25,6 @@ -
-