Skip to content

Commit

Permalink
Merge pull request #112 from subugoe/fixExtendedSearch
Browse files Browse the repository at this point in the history
Fix extended search
  • Loading branch information
ipf committed Oct 28, 2015
2 parents bd06370 + 8e28ea6 commit b3aa6a4
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions Classes/Service/SolrServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public function setCounter()

/**
* Returns the number of results per page using the first of:
* * query parameter »count«
* * TypoScript setting »paging.perPage«
* query parameter »count«
* TypoScript setting »paging.perPage«
* limited by the setting »paging.maximumPerPage«
*
* @param array $arguments overrides $this->requestArguments if set
Expand Down Expand Up @@ -192,7 +192,6 @@ protected function addEDisMax()
$this->query->getEDisMax();
}


/**
* @return \Solarium\Client
*/
Expand Down Expand Up @@ -603,11 +602,7 @@ protected function queryComponentsForQueryParameters($queryParameters)
}

if ($queryPart) {
if (is_array($queryParameters[$fieldID]) && empty($queryParameters[$fieldID]['term'])) {
// TODO some handling
} else {
$queryComponents[$fieldID] = $queryPart;
}
$queryComponents[$fieldID] = $queryPart;
}
}
}
Expand All @@ -631,7 +626,6 @@ protected function queryComponentsForQueryParameters($queryParameters)
*/
protected function addHighlighting($arguments)
{

$highlightConfig = SettingsUtility::getMergedSettings('highlight', $this->settings);

if ($highlightConfig && $highlightConfig['fields'] && count($highlightConfig['fields']) > 0) {
Expand Down Expand Up @@ -744,7 +738,6 @@ protected function addSortStringForQuery($sortString)
continue;
}
}

$this->query->addSort($sortCriterionParts[0], $sortDirection);
} else {
$message = sprintf('find: sort criterion »%s« does not have the required form »fieldName [asc|desc]«. Ignoring it.',
Expand All @@ -756,29 +749,52 @@ protected function addSortStringForQuery($sortString)
}

/**
* Main starting point for blank index action
* Returns request arguments which are set.
* @return array
*/
protected function getFilteredRequestArguments()
{
$filteredQueryParameters = [];
$requestArguments = $this->getRequestArguments();
if (array_key_exists('q', $requestArguments)) {
$queryParameters = $requestArguments['q'];
foreach ($queryParameters as $argumentsKey => $arguments) {
if (is_array($arguments) && !empty($arguments)) {
foreach ($arguments as $argumentKey => $argument) {
if (!empty($argument)) {
$filteredQueryParameters[$argumentsKey][$argumentKey] = $argument;
}
}
} else {
if (!empty($arguments)) {
$filteredQueryParameters[$argumentsKey] = $arguments;
}
}
}
}
return $filteredQueryParameters;
}

/**
* Main starting point for blank index action.
* @return array
*/
public function getDefaultQuery()
{
$this->createQueryForArguments($this->getRequestArguments());
$error = NULL;
$resultSet = NULL;

try {
$resultSet = $this->connection->execute($this->query);
} catch (HttpException $exception) {

LoggerUtility::logError(
'find: Solr Exception (Timeout?)',
[
'requestArguments' => $this->getRequestArguments(),
'exception' => LoggerUtility::exceptionToArray($exception)
]
);

$error = ['solr' => $exception];

}

return [
Expand All @@ -796,13 +812,7 @@ public function getDefaultQuery()
protected function createQueryForArguments($arguments)
{
$this->createQuery();

// Build query string.
$queryParameters = [];
if (array_key_exists('q', $arguments)) {
$queryParameters = $arguments['q'];
}

$queryParameters = $this->getFilteredRequestArguments();
$queryComponents = $this->queryComponentsForQueryParameters($queryParameters);
$queryString = implode(' ' . Query::QUERY_OPERATOR_AND . ' ', $queryComponents);
$this->query->setQuery($queryString);
Expand Down Expand Up @@ -866,7 +876,6 @@ protected function createQuery()
$this->query = $this->connection->createSelect();
$this->addFeatures();
$this->addTypoScriptFilters();

$this->setConfigurationValue('solarium', $this->query);
}

Expand Down Expand Up @@ -930,7 +939,6 @@ protected function addResultCountOptionsToTemplate($arguments)
$this->setConfigurationValue('resultCountOptions', $resultCountOptions);
}


/**
* Sets up $query’s sort order from URL arguments or the TypoScript default.
*
Expand Down

0 comments on commit b3aa6a4

Please sign in to comment.