- added facet fields as search parameter
- added faceting search result as serialized metadata to result list
This commit is contained in:
parent
16ea35bc87
commit
8f69b1f98b
|
@ -156,17 +156,17 @@ class tx_dlf_solr {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Processes a search request against the configured Solr instance.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param tx_dlf_solr_search $search: Search info
|
||||
* @param tx_dlf_solr_search $search the search settings
|
||||
*
|
||||
* @return integer First unused core number found
|
||||
* @return tx_dlf_list a list instance that contains search results
|
||||
*/
|
||||
public static function search($searchStruct) {
|
||||
|
||||
t3lib_div::devLog('[search] search='.$searchStruct, 'dlf', t3lib_div::SYSLOG_SEVERITY_INFO);
|
||||
t3lib_div::devLog('[tx_dlf_solr.search] search='.$searchStruct, 'dlf', t3lib_div::SYSLOG_SEVERITY_INFO);
|
||||
|
||||
$solr = self::solrConnect($searchStruct->core);
|
||||
|
||||
|
@ -176,21 +176,33 @@ class tx_dlf_solr {
|
|||
|
||||
}
|
||||
|
||||
// Extract facet queries.
|
||||
$facetParams = array();
|
||||
// Extract filter query.
|
||||
$searchParameters = array();
|
||||
|
||||
if (count($searchStruct->filterQuery) > 0) {
|
||||
if (!empty($searchStruct->filterQuery)) {
|
||||
|
||||
$facetParams['facet'] = 'true';
|
||||
|
||||
$facetParams['fq'] = $searchStruct->filterQuery;
|
||||
|
||||
t3lib_div::devLog('[search] using facetParams='.tx_dlf_helper::array_toString($facetParams), 'dlf', t3lib_div::SYSLOG_SEVERITY_INFO);
|
||||
|
||||
}
|
||||
$searchParameters['fq'] = $searchStruct->filterQuery;
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (count($searchStruct->facetFields) > 0) {
|
||||
|
||||
$searchParameters['facet'] = 'true';
|
||||
|
||||
$searchParameters['facet.field'] = $searchStruct->facetFields;
|
||||
|
||||
}
|
||||
|
||||
if (count($searchParameters) > 0) {
|
||||
|
||||
t3lib_div::devLog('[tx_dlf_solr.search] searchParameters='.tx_dlf_helper::array_toString($searchParameters), 'dlf', t3lib_div::SYSLOG_SEVERITY_INFO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Perform search.
|
||||
$query = $solr->search($searchStruct->queryString, 0, $searchStruct->limit, $facetParams);
|
||||
$query = $solr->search($searchStruct->queryString, 0, $searchStruct->limit, $searchParameters);
|
||||
|
||||
$_list = array ();
|
||||
|
||||
|
@ -309,7 +321,14 @@ class tx_dlf_solr {
|
|||
'hitCount' => $hitCount
|
||||
)
|
||||
);
|
||||
|
||||
// Add facet result if requested in search.
|
||||
if ($searchParameters['facet'] === 'true') {
|
||||
|
||||
$_metadata['result']['facet.fields'] = serialize($query->facet_counts->facet_fields);
|
||||
|
||||
}
|
||||
|
||||
$list->metadata = $_metadata;
|
||||
|
||||
$list->save();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
/***************************************************************
|
||||
* Copyright notice
|
||||
*
|
||||
* (c) 2012
|
||||
* (c) 2012, Zeutschel GmbH
|
||||
* All rights reserved
|
||||
*
|
||||
* This script is part of the TYPO3 project. The TYPO3 project is
|
||||
|
@ -28,33 +28,73 @@
|
|||
|
||||
/**
|
||||
* Document class 'tx_dlf_solr_search' for the 'dlf' extension.
|
||||
*
|
||||
* @author
|
||||
* @copyright Copyright (c) 2012
|
||||
* @package TYPO3
|
||||
* @subpackage tx_dlf
|
||||
* @access public
|
||||
*/
|
||||
*
|
||||
* @author Henrik Lochmann <dev@mentalmotive.com>
|
||||
* @copyright Copyright (c) 2012, Zeutschel GmbH
|
||||
* @package TYPO3
|
||||
* @subpackage tx_dlf
|
||||
* @access public
|
||||
*/
|
||||
class tx_dlf_solr_search {
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $core;
|
||||
|
||||
protected $pid;
|
||||
|
||||
protected $queryString;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $facetFields;
|
||||
|
||||
/**
|
||||
* @var string the filter query
|
||||
*/
|
||||
protected $filterQuery;
|
||||
|
||||
protected $limit;
|
||||
|
||||
protected $source;
|
||||
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $label;
|
||||
|
||||
protected $description;
|
||||
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $limit;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
*/
|
||||
protected $pid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $queryString;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* Returns the passed $list parameter unchaned, if it is not NULL. Otherwise,
|
||||
* the tx_dlf_list instance stored in the current user session is returned.
|
||||
*
|
||||
* @param tx_dlf_list $list the tx_dlf_list instance to ensure
|
||||
*
|
||||
* @return tx_dlf_list the session list or the passed parameter if it is not NULL.
|
||||
*/
|
||||
protected static function ensureList($list) {
|
||||
|
||||
if ($list == NULL) {
|
||||
|
@ -162,6 +202,12 @@ class tx_dlf_solr_search {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the query string of the search instance or '*'
|
||||
* if query string and filter query are empty.
|
||||
*
|
||||
* @return string the query string of the search instance
|
||||
*/
|
||||
protected function getQueryString() {
|
||||
|
||||
// An empty query string leads to *-query, while the filter query is non-empty.
|
||||
|
@ -175,6 +221,12 @@ class tx_dlf_solr_search {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the $label and $description fields with corresponding values
|
||||
* of the user session list.
|
||||
*
|
||||
* @param void
|
||||
*/
|
||||
public function restoreHeader($list = NULL) {
|
||||
|
||||
$list = self::ensureList($list);
|
||||
|
@ -185,6 +237,12 @@ class tx_dlf_solr_search {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the $filterQuery field with corresponding value
|
||||
* of the user session list.
|
||||
*
|
||||
* @param void
|
||||
*/
|
||||
public function restoreFilterQuery($list = NULL) {
|
||||
|
||||
$list = self::ensureList($list);
|
||||
|
@ -197,11 +255,20 @@ class tx_dlf_solr_search {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the $queryString field with corresponding value
|
||||
* of the user session list.
|
||||
*
|
||||
* @param void
|
||||
*/
|
||||
public function restoreQueryString($list = NULL) {
|
||||
|
||||
$list = self::ensureList($list);
|
||||
|
||||
if (!empty($list->metadata['options']) && $list->metadata['options']['source'] === 'search') {
|
||||
if (!empty($list->metadata['options'])
|
||||
// only search and facets plugins perform searches, yet
|
||||
&& (($list->metadata['options']['source'] === 'search') || ($list->metadata['options']['source'] === 'facets'))) {
|
||||
|
||||
$this->queryString = $list->metadata['options']['select'];
|
||||
|
||||
|
|
Loading…
Reference in New Issue