Skip to content

Commit

Permalink
Merge pull request #5516 from laboro/fix/OEE-641_1.7
Browse files Browse the repository at this point in the history
OEE-641: Elastic search doesn't support search with middle name
  • Loading branch information
ignat-s committed Sep 25, 2015
2 parents df0dcde + ea0c227 commit 45ef20d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/Oro/Bundle/FormBundle/Autocomplete/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,24 @@ protected function searchEntities($search, $firstResult, $maxResults)
$resultEntities = [];

if ($entityIds) {
$resultEntities = $this->getEntitiesByIds($entityIds);
$unsortedEntities = $this->getEntitiesByIds($entityIds);

/**
* We need to sort entities in the same order given by method searchIds.
*
* @todo Should be not necessary after implementation of BAP-5691.
*/
$entityByIdHash = [];

foreach ($unsortedEntities as $entity) {
$entityByIdHash[$this->getPropertyValue($this->idFieldName, $entity)] = $entity;
}

foreach ($entityIds as $entityId) {
if (isset($entityByIdHash[$entityId])) {
$resultEntities[] = $entityByIdHash[$entityId];
}
}
}

return $resultEntities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,16 @@ public function searchDataProvider()
'getResult',
array(),
array(
/**
* test sorting works correct
*/
array(self::TEST_ID_FIELD => 3,'name' => 'Jack'),
$this->createMockEntity(
array(self::TEST_ID_FIELD => 1, 'name' => 'John', 'email' => '[email protected]')
),
$this->createMockEntity(
array(self::TEST_ID_FIELD => 2, 'name' => 'Jane', 'email' => '[email protected]')
),
array(self::TEST_ID_FIELD => 3,'name' => 'Jack'),
),
$this->createStubEntityWithProperties(
array(
self::TEST_ID_FIELD => 4,
Expand Down Expand Up @@ -337,11 +340,14 @@ public function searchDataProvider()
'getResult',
array(),
array(
/**
* test sorting works correct
*/
$this->createMockEntity(
array(self::TEST_ID_FIELD => 1, 'name' => 'John', 'email' => 'john@example.com')
array(self::TEST_ID_FIELD => 2, 'name' => 'Jane', 'email' => 'jane@example.com')
),
$this->createMockEntity(
array(self::TEST_ID_FIELD => 2, 'name' => 'Jane', 'email' => 'jane@example.com')
array(self::TEST_ID_FIELD => 1, 'name' => 'John', 'email' => 'john@example.com')
)
)
),
Expand Down

0 comments on commit 45ef20d

Please sign in to comment.