diff --git a/dlf/common/class.tx_dlf_list.php b/dlf/common/class.tx_dlf_list.php index 998044dc..205653c0 100644 --- a/dlf/common/class.tx_dlf_list.php +++ b/dlf/common/class.tx_dlf_list.php @@ -371,7 +371,7 @@ class tx_dlf_list implements t3lib_Singleton { */ public function __construct(array $elements = array (), array $metadata = array ()) { - if (!$elements && !$metadata) { + if (empty($elements) && empty($metadata)) { // Let's check the user's session. $sessionData = tx_dlf_helper::loadFromSession(get_class($this)); diff --git a/dlf/common/class.tx_dlf_solr.php b/dlf/common/class.tx_dlf_solr.php index 6ffcba9d..f5785573 100644 --- a/dlf/common/class.tx_dlf_solr.php +++ b/dlf/common/class.tx_dlf_solr.php @@ -62,14 +62,6 @@ class tx_dlf_solr { */ public static $extKey = 'dlf'; - /** - * This holds the filter query - * - * @var array - * @access protected - */ - protected $filter = array (); - /** * This holds the max results * @@ -86,6 +78,14 @@ class tx_dlf_solr { */ protected $numberOfHits = 0; + /** + * This holds the additional query parameters + * + * @var array + * @access protected + */ + protected $params = array (); + /** * Is the search instantiated successfully? * @@ -259,16 +259,16 @@ class tx_dlf_solr { } // Perform search. - $query = $this->service->search($query, 0, $this->limit, $this->filter); + $results = $this->service->search($query, 0, $this->limit, $this->params); - $this->numberOfHits = count($query->response->docs); + $this->numberOfHits = count($results->response->docs); $toplevel = array (); $checks = array (); // Get metadata configuration. - if ($numHits) { + if ($this->numberOfHits > 0) { $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'tx_dlf_metadata.index_name AS index_name,tx_dlf_metadata.tokenized AS tokenized,tx_dlf_metadata.indexed AS indexed,tx_dlf_metadata.is_listed AS is_listed,tx_dlf_metadata.is_sortable AS is_sortable', @@ -305,7 +305,7 @@ class tx_dlf_solr { $i = 0; // Process results. - foreach ($query->response->docs as $doc) { + foreach ($results->response->docs as $doc) { // Prepate document's metadata. $docMeta = array (); @@ -471,7 +471,7 @@ class tx_dlf_solr { 'options' => array ( 'source' => 'search', 'select' => $query, - 'filter' => $this->filter, + 'params' => $this->params, 'order' => 'relevance' ) ); @@ -534,21 +534,6 @@ class tx_dlf_solr { } - /** - * This sets $this->filter via __set() - * - * @access protected - * - * @param array $value: The filter query - * - * @return void - */ - protected function _setFilter(array $value) { - - $this->filter = $value; - - } - /** * This sets $this->limit via __set() * @@ -564,6 +549,21 @@ class tx_dlf_solr { } + /** + * This sets $this->params via __set() + * + * @access protected + * + * @param array $value: The query parameters + * + * @return void + */ + protected function _setParams(array $value) { + + $this->params = $value; + + } + /** * This magic method is called each time an invisible property is referenced from the object * diff --git a/dlf/plugins/collection/class.tx_dlf_collection.php b/dlf/plugins/collection/class.tx_dlf_collection.php index 2d1fae6c..01e62a2f 100644 --- a/dlf/plugins/collection/class.tx_dlf_collection.php +++ b/dlf/plugins/collection/class.tx_dlf_collection.php @@ -283,7 +283,7 @@ class tx_dlf_collection extends tx_dlf_plugin { 'options' => array ( 'source' => 'collection', 'select' => $id, - 'filter' => array ('collection_faceting:"'.$resArray['index_name'].'"'), + 'params' => array ('fq' => array ('collection_faceting:"'.$resArray['index_name'].'"')), 'order' => 'title' ) ); diff --git a/dlf/plugins/search/class.tx_dlf_search.php b/dlf/plugins/search/class.tx_dlf_search.php index 8fa701a9..abf9d50b 100644 --- a/dlf/plugins/search/class.tx_dlf_search.php +++ b/dlf/plugins/search/class.tx_dlf_search.php @@ -133,7 +133,7 @@ class tx_dlf_search extends tx_dlf_plugin { foreach (t3lib_div::trimExplode(',', $this->conf['facets'], TRUE) as $facet) { - $facets[$facet] = tx_dlf_helper::translate($facet, 'tx_dlf_metadata', $this->conf['pages']); + $facets[$facet.'_faceting'] = tx_dlf_helper::translate($facet, 'tx_dlf_metadata', $this->conf['pages']); } @@ -146,6 +146,8 @@ class tx_dlf_search extends tx_dlf_plugin { $TSconfig['special.']['facets'] = $facets; + $TSconfig['special.']['limit'] = max(intval($this->conf['limitFacets']), 1); + $TSconfig = t3lib_div::array_merge_recursive_overrule($this->conf['facetsConf.'], $TSconfig); return $this->cObj->HMENU($TSconfig); @@ -171,21 +173,26 @@ class tx_dlf_search extends tx_dlf_plugin { if ($field == 'owner_faceting') { // Translate name of holding library. - $entryArray['title'] = tx_dlf_helper::translate($value, 'tx_dlf_libraries', $this->conf['pages']); + $entryArray['title'] = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_libraries', $this->conf['pages'])); } elseif ($field == 'type_faceting') { // Translate document type. - $entryArray['title'] = tx_dlf_helper::translate($value, 'tx_dlf_structures', $this->conf['pages']); + $entryArray['title'] = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_structures', $this->conf['pages'])); + + } elseif ($field == 'collection_faceting') { + + // Translate document type. + $entryArray['title'] = htmlspecialchars(tx_dlf_helper::translate($value, 'tx_dlf_collections', $this->conf['pages'])); } elseif ($field == 'language_faceting') { // Translate ISO 639 language code. - $entryArray['title'] = tx_dlf_helper::getLanguageName($value); + $entryArray['title'] = htmlspecialchars(tx_dlf_helper::getLanguageName($value)); } else { - $entryArray['title'] = $value; + $entryArray['title'] = htmlspecialchars($value); } @@ -194,14 +201,14 @@ class tx_dlf_search extends tx_dlf_plugin { $entryArray['doNotLinkIt'] = 0; // Check if facet is already selected. - $index = array_search($field.':"'.$value.'"', $search['fq']); + $index = array_search($field.':"'.$value.'"', $search['params']['fq']); if ($index !== FALSE) { // Facet is selected, thus remove it from filter. - unset($search['fq'][$index]); + unset($search['params']['fq'][$index]); - $search['fq'] = array_values($search['fq']); + $search['params']['fq'] = array_values($search['params']['fq']); $entryArray['ITEM_STATE'] = 'CUR'; @@ -210,13 +217,13 @@ class tx_dlf_search extends tx_dlf_plugin { } else { // Facet is not selected, thus add it to filter. - $search['fq'][] = $field.':"'.$value.'"'; + $search['params']['fq'][] = $field.':"'.$value.'"'; $entryArray['ITEM_STATE'] = 'NO'; } - $entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('query' => $search['query'], 'fq' => $search['fq'])); + $entryArray['_OVERRIDE_HREF'] = $this->pi_linkTP_keepPIvars_url(array ('query' => $search['query'], 'fq' => $search['params']['fq'])); return $entryArray; @@ -313,13 +320,13 @@ class tx_dlf_search extends tx_dlf_plugin { } // Set search parameters. - $solr->limit = $this->conf['limit']; + $solr->limit = max(intval($this->conf['limit']), 1); $solr->cPid = $this->conf['pages']; if (!empty($this->piVars['fq'])) { - $solr->filter = $this->piVars['fq']; + $solr->params = array ('fq' => $this->piVars['fq']); } @@ -365,10 +372,10 @@ class tx_dlf_search extends tx_dlf_plugin { $menuArray = array (); - // Set default values for facet search. + // Set default value for facet search. $search = array ( 'query' => '*', - 'fq' => array () + 'params' => array () ); // Extract query and filter from last search. @@ -382,7 +389,7 @@ class tx_dlf_search extends tx_dlf_plugin { } - $search['fq'] = $list->metadata['options']['filter']; + $search['params'] = $list->metadata['options']['params']; } @@ -401,29 +408,28 @@ class tx_dlf_search extends tx_dlf_plugin { } - $params = array ( - 'facet' => 'true', - 'fq' => $search['fq'], - 'facet.field' => array () - ); + // Set needed parameters for facet search. + if (empty($search['params']['fq'])) { - foreach ($this->conf['facets'] as $field => $label) { - - $params['facet.field'][] = $field.'_faceting'; + $search['params']['fq'] = array (); } + $search['params']['facet'] = 'true'; + + $search['params']['facet.field'] = array_keys($this->conf['facets']); + // Perform search. - $results = $solr->service->search($search['query'], 0, $this->conf['limit'], $params); + $results = $solr->service->search($search['query'], 0, $this->conf['limit'], $search['params']); // Process results. foreach ($results->facet_counts->facet_fields as $field => $values) { $entryArray = array (); - $entryArray['title'] = $this->conf['facets'][$field]; + $entryArray['title'] = htmlspecialchars($this->conf['facets'][$field]); - $entryArray['count'] = 0; + $entryArray['count'] = count((array) $values); $entryArray['_OVERRIDE_HREF'] = ''; @@ -431,18 +437,29 @@ class tx_dlf_search extends tx_dlf_plugin { $entryArray['ITEM_STATE'] = 'NO'; + // Count number of facet values. + $i = 0; + foreach ($values as $value => $count) { if ($count > 0) { $hasValue = TRUE; - $entryArray['count']++; - $entryArray['ITEM_STATE'] = 'IFSUB'; $entryArray['_SUB_MENU'][] = $this->getFacetsMenuEntry($field, $value, $count, $search, $entryArray['ITEM_STATE']); + if (++$i == $this->conf['limit']) { + + break; + + } + + } else { + + break; + } } diff --git a/dlf/plugins/search/flexform.xml b/dlf/plugins/search/flexform.xml index 2e8af68d..ce943514 100644 --- a/dlf/plugins/search/flexform.xml +++ b/dlf/plugins/search/flexform.xml @@ -44,11 +44,12 @@ + FIELD:pages:REQ:true 1 input - required,num,int + num,int 50000 @@ -69,6 +70,22 @@ + + + FIELD:pages:REQ:true + 1 + + + input + num,int + + 1 + 100 + + 15 + + + 1 diff --git a/dlf/plugins/search/locallang.xml b/dlf/plugins/search/locallang.xml index ca3617d4..89bdcf1b 100644 --- a/dlf/plugins/search/locallang.xml +++ b/dlf/plugins/search/locallang.xml @@ -10,6 +10,7 @@ + @@ -23,6 +24,7 @@ + diff --git a/dlf/plugins/search/template.tmpl b/dlf/plugins/search/template.tmpl index 8cb147c4..00e572df 100644 --- a/dlf/plugins/search/template.tmpl +++ b/dlf/plugins/search/template.tmpl @@ -4,6 +4,6 @@ ###ADDITIONAL_INPUTS### - ###FACETS_MENU### +
###FACETS_MENU###
\ No newline at end of file