mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-23 11:36:11 +01:00
[TASK] Process feedback and fix unit-tests
This commit is contained in:
parent
028914e789
commit
a50cbf25a2
9 changed files with 54 additions and 24 deletions
|
@ -55,10 +55,6 @@ class MappingFactory implements Singleton
|
|||
$mapping->setType($type);
|
||||
|
||||
$configuration = $this->getConfiguration($type->getName());
|
||||
if (isset($configuration['_all'])) {
|
||||
$mapping->setAllField($configuration['_all']);
|
||||
unset($configuration['_all']);
|
||||
}
|
||||
$mapping->setProperties($configuration);
|
||||
|
||||
return $mapping;
|
||||
|
|
|
@ -25,6 +25,7 @@ use Codappix\SearchCore\Connection\ConnectionInterface;
|
|||
use Codappix\SearchCore\Connection\FacetRequestInterface;
|
||||
use Codappix\SearchCore\Connection\SearchRequestInterface;
|
||||
use Codappix\SearchCore\Domain\Search\SearchService;
|
||||
use Codappix\SearchCore\Utility\ArrayUtility as CustomArrayUtility;
|
||||
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||
|
||||
/**
|
||||
|
@ -101,7 +102,7 @@ class SearchRequest implements SearchRequestInterface
|
|||
public function setFilter(array $filter)
|
||||
{
|
||||
$filter = ArrayUtility::removeArrayEntryByValue($filter, '');
|
||||
$this->filter = ArrayUtility::removeNullValuesRecursive($filter);
|
||||
$this->filter = CustomArrayUtility::removeEmptyElementsRecursively($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,9 +124,11 @@ class QueryFactory
|
|||
'query' => $searchRequest->getSearchTerm(),
|
||||
];
|
||||
|
||||
$fieldsToQuery = GeneralUtility::trimExplode(',', $this->configuration->getIfExists('searching.fields.query'), true);
|
||||
if (!empty($fieldsToQuery)) {
|
||||
try {
|
||||
$fieldsToQuery = GeneralUtility::trimExplode(',', $this->configuration->get('searching.fields.query'), true);
|
||||
$matchExpression['fields'] = $fieldsToQuery;
|
||||
} catch (InvalidArgumentException $e) {
|
||||
// Nothing configured
|
||||
}
|
||||
|
||||
$minimumShouldMatch = $this->configuration->getIfExists('searching.minimumShouldMatch');
|
||||
|
|
35
Classes/Utility/ArrayUtility.php
Normal file
35
Classes/Utility/ArrayUtility.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Utility;
|
||||
|
||||
/**
|
||||
* Utility: Array
|
||||
* @package Codappix\SearchCore\Utility
|
||||
*/
|
||||
class ArrayUtility
|
||||
{
|
||||
|
||||
/**
|
||||
* Recursively removes empty array elements.
|
||||
*
|
||||
* @param array $array
|
||||
* @return array the modified array
|
||||
* @see \TYPO3\CMS\Extbase\Utility\ArrayUtility::removeEmptyElementsRecursively Removed in TYPO3 v9
|
||||
*/
|
||||
public static function removeEmptyElementsRecursively(array $array): array
|
||||
{
|
||||
$result = $array;
|
||||
foreach ($result as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result[$key] = self::removeEmptyElementsRecursively($value);
|
||||
if ($result[$key] === []) {
|
||||
unset($result[$key]);
|
||||
}
|
||||
} elseif ($value === null) {
|
||||
unset($result[$key]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
|
@ -46,10 +46,6 @@ class MappingFactoryTest extends AbstractUnitTestCase
|
|||
{
|
||||
$indexName = 'someIndex';
|
||||
$configuration = [
|
||||
'_all' => [
|
||||
'type' => 'text',
|
||||
'analyzer' => 'ngram4',
|
||||
],
|
||||
'channel' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
|
@ -64,16 +60,8 @@ class MappingFactoryTest extends AbstractUnitTestCase
|
|||
->method('get')
|
||||
->with('indexing.' . $indexName . '.mapping')
|
||||
->willReturn($configuration);
|
||||
|
||||
$mapping = $this->subject->getMapping($type)->toArray()[$indexName];
|
||||
$this->assertArraySubset(
|
||||
[
|
||||
'_all' => $configuration['_all']
|
||||
],
|
||||
$mapping,
|
||||
true,
|
||||
'Configuration of _all field was not set for mapping.'
|
||||
);
|
||||
|
||||
$this->assertArraySubset(
|
||||
[
|
||||
'channel' => $configuration['channel']
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Codappix\Tests\Unit\Controller;
|
|||
|
||||
use Codappix\SearchCore\Controller\SearchController;
|
||||
use Codappix\SearchCore\Domain\Model\SearchRequest;
|
||||
use Codappix\SearchCore\Domain\Search\SearchService;
|
||||
use Codappix\SearchCore\Domain\Search\CachedSearchService;
|
||||
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
|
||||
use TYPO3\CMS\Extbase\Mvc\Web\Request;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
@ -54,7 +54,7 @@ class SearchControllerTest extends AbstractUnitTestCase
|
|||
|
||||
parent::setUp();
|
||||
|
||||
$searchService = $this->getMockBuilder(SearchService::class)
|
||||
$searchService = $this->getMockBuilder(CachedSearchService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = new Request();
|
||||
|
|
|
@ -82,6 +82,7 @@ class AbstractIndexerTest extends AbstractUnitTestCase
|
|||
$expectedRecord['new_test_field'] = 'test';
|
||||
$expectedRecord['new_test_field2'] = 'test' . PHP_EOL . 'test';
|
||||
$expectedRecord['search_abstract'] = '';
|
||||
$expectedRecord['search_document_type'] = 'testTable';
|
||||
|
||||
$this->dataProcessorService->expects($this->any())
|
||||
->method('executeDataProcessor')
|
||||
|
@ -137,6 +138,7 @@ class AbstractIndexerTest extends AbstractUnitTestCase
|
|||
$record = ['field 1' => 'test'];
|
||||
$expectedRecord = $record;
|
||||
$expectedRecord['search_abstract'] = '';
|
||||
$expectedRecord['search_document_type'] = 'testTable';
|
||||
|
||||
$this->configuration->expects($this->exactly(2))
|
||||
->method('get')
|
||||
|
|
|
@ -45,6 +45,10 @@ class SearchRequestTest extends AbstractUnitTestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for emptyFilterWillNotBeSet()
|
||||
* @return array
|
||||
*/
|
||||
public function possibleEmptyFilter()
|
||||
{
|
||||
return [
|
||||
|
|
|
@ -428,7 +428,7 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
['searching.fieldValueFactor']
|
||||
)
|
||||
->will($this->onConsecutiveCalls(
|
||||
'_all, field1, field2',
|
||||
'field1, field2',
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
$this->throwException(new InvalidArgumentException),
|
||||
|
@ -445,7 +445,6 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
'type' => 'most_fields',
|
||||
'query' => 'SearchWord',
|
||||
'fields' => [
|
||||
'_all',
|
||||
'field1',
|
||||
'field2',
|
||||
],
|
||||
|
@ -662,6 +661,9 @@ class QueryFactoryTest extends AbstractUnitTestCase
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function configureConfigurationMockWithDefault()
|
||||
{
|
||||
$this->configuration->expects($this->any())
|
||||
|
|
Loading…
Reference in a new issue