Refactor filter query handling
This commit is contained in:
parent
c408e1c815
commit
7b49f01bb8
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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'
|
||||
)
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,11 +44,12 @@
|
|||
</solrcore>
|
||||
<limit>
|
||||
<TCEforms>
|
||||
<displayCond>FIELD:pages:REQ:true</displayCond>
|
||||
<exclude>1</exclude>
|
||||
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.limit</label>
|
||||
<config>
|
||||
<type>input</type>
|
||||
<eval>required,num,int</eval>
|
||||
<eval>num,int</eval>
|
||||
<default>50000</default>
|
||||
</config>
|
||||
</TCEforms>
|
||||
|
@ -69,6 +70,22 @@
|
|||
</config>
|
||||
</TCEforms>
|
||||
</facets>
|
||||
<limitFacets>
|
||||
<TCEforms>
|
||||
<displayCond>FIELD:pages:REQ:true</displayCond>
|
||||
<exclude>1</exclude>
|
||||
<label>LLL:EXT:dlf/plugins/search/locallang.xml:tt_content.pi_flexform.limitFacets</label>
|
||||
<config>
|
||||
<type>input</type>
|
||||
<eval>num,int</eval>
|
||||
<range>
|
||||
<lower>1</lower>
|
||||
<upper>100</upper>
|
||||
</range>
|
||||
<default>15</default>
|
||||
</config>
|
||||
</TCEforms>
|
||||
</limitFacets>
|
||||
<targetPid>
|
||||
<TCEforms>
|
||||
<exclude>1</exclude>
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<label index="tt_content.pi_flexform.solrcore">Solr Core</label>
|
||||
<label index="tt_content.pi_flexform.limit">Maximum results</label>
|
||||
<label index="tt_content.pi_flexform.facets">Show these facets</label>
|
||||
<label index="tt_content.pi_flexform.limitFacets">Maximum facet values</label>
|
||||
<label index="tt_content.pi_flexform.targetPid">Target page (with "DLF: List View" plugin)</label>
|
||||
<label index="tt_content.pi_flexform.separator">Separator for metadata in TS array</label>
|
||||
<label index="tt_content.pi_flexform.templateFile">Template file</label>
|
||||
|
@ -23,6 +24,7 @@
|
|||
<label index="tt_content.pi_flexform.solrcore">Solr Kern</label>
|
||||
<label index="tt_content.pi_flexform.limit">Maximale Ergebnismenge</label>
|
||||
<label index="tt_content.pi_flexform.facets">Diese Facetten anzeigen</label>
|
||||
<label index="tt_content.pi_flexform.limitFacets">Maximale Facettenwerte</label>
|
||||
<label index="tt_content.pi_flexform.targetPid">Zielseite (mit Plugin "DLF: Listenansicht")</label>
|
||||
<label index="tt_content.pi_flexform.separator">Trennzeichen für Metadaten im TS-Array</label>
|
||||
<label index="tt_content.pi_flexform.templateFile">HTML-Template</label>
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
<input type="text" id="###FIELD_QUERY###" name="###FIELD_QUERY###" value="###QUERY###" class="tx-dlf-search-query" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
|
||||
<input type="submit" value="###LABEL_SUBMIT###" />
|
||||
###ADDITIONAL_INPUTS###
|
||||
###FACETS_MENU###
|
||||
</form>
|
||||
<div class="tx-dlf-search-facets">###FACETS_MENU###</div>
|
||||
<!-- ###TEMPLATE### -->
|
Loading…
Reference in New Issue