mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
Merge pull request #694 from romainneutron/fix-1535
[3.8] Fix #1535 : API does not display search engine suggestions correctly
This commit is contained in:
@@ -33,7 +33,7 @@ class SearchEngineSuggestion
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->suggestion = $suggestion;
|
||||
$this->hits = (int) $hits;
|
||||
$this->hits = null !== $hits ? (int) $hits : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,4 +66,16 @@ class SearchEngineSuggestion
|
||||
return $this->hits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the suggestion as an array representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
return array(
|
||||
'query' => $this->getSuggestion(),
|
||||
'hits' => $this->getHits(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineOptions;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Border\File;
|
||||
use Alchemy\Phrasea\Border\Attribute\Status;
|
||||
@@ -916,7 +917,9 @@ class API_V1_adapter extends API_V1_Abstract
|
||||
'warning' => $search_result->getWarning(),
|
||||
'query_time' => $search_result->getDuration(),
|
||||
'search_indexes' => $search_result->getIndexes(),
|
||||
'suggestions' => $search_result->getSuggestions()->toArray(),
|
||||
'suggestions' => array_map(function (SearchEngineSuggestion $suggestion) {
|
||||
return $suggestion->toArray();
|
||||
}, $search_result->getSuggestions()->toArray()),
|
||||
'results' => array(),
|
||||
'query' => $search_result->getQuery(),
|
||||
);
|
||||
|
@@ -12,7 +12,7 @@ class SearchEngineSuggestionTest extends \PhraseanetPHPUnitAbstract
|
||||
public function testSetUp()
|
||||
{
|
||||
$words = 'plutôt cela';
|
||||
$query = 'Katy Query';
|
||||
$query = 'Batman';
|
||||
$hits = 42;
|
||||
|
||||
$suggestion = new SearchEngineSuggestion($query, $words, $hits);
|
||||
@@ -20,4 +20,36 @@ class SearchEngineSuggestionTest extends \PhraseanetPHPUnitAbstract
|
||||
$this->assertEquals($query, $suggestion->getQuery());
|
||||
$this->assertEquals($words, $suggestion->getSuggestion());
|
||||
}
|
||||
|
||||
public function testNullHits()
|
||||
{
|
||||
$words = 'plutôt cela';
|
||||
$query = 'Batman';
|
||||
$hits = null;
|
||||
|
||||
$suggestion = new SearchEngineSuggestion($query, $words, $hits);
|
||||
$this->assertNull($suggestion->getHits());
|
||||
$this->assertEquals($query, $suggestion->getQuery());
|
||||
$this->assertEquals($words, $suggestion->getSuggestion());
|
||||
}
|
||||
|
||||
public function testToArray()
|
||||
{
|
||||
$words = 'plutôt cela';
|
||||
$query = 'Batman';
|
||||
$hits = 35;
|
||||
|
||||
$suggestion = new SearchEngineSuggestion($query, $words, $hits);
|
||||
$this->assertEquals(array('query' => $words, 'hits' => 35), $suggestion->toArray());
|
||||
}
|
||||
|
||||
public function testToArrayWithNullValue()
|
||||
{
|
||||
$words = 'plutôt cela';
|
||||
$query = 'Batman';
|
||||
$hits = null;
|
||||
|
||||
$suggestion = new SearchEngineSuggestion($query, $words, $hits);
|
||||
$this->assertEquals(array('query' => $words, 'hits' => null), $suggestion->toArray());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user