mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
Fix #1118 : API does not return records starting at right offset
This commit is contained in:
@@ -984,7 +984,7 @@ class API_V1_adapter extends API_V1_Abstract
|
|||||||
|
|
||||||
$search_engine->reset_cache();
|
$search_engine->reset_cache();
|
||||||
|
|
||||||
$search_result = $search_engine->query_per_offset($params['query'], $params["offset_start"], $perPage);
|
$search_result = $search_engine->query_per_offset($params['query'], $params["offset_start"] + 1, $perPage);
|
||||||
|
|
||||||
$ret = array(
|
$ret = array(
|
||||||
'offset_start' => $params["offset_start"],
|
'offset_start' => $params["offset_start"],
|
||||||
|
@@ -230,8 +230,6 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
|
|||||||
$this->current_page = $page;
|
$this->current_page = $page;
|
||||||
$this->perPage = $perPage;
|
$this->perPage = $perPage;
|
||||||
|
|
||||||
$page = $this->get_current_page();
|
|
||||||
|
|
||||||
if (trim($query) === '')
|
if (trim($query) === '')
|
||||||
$query = "all";
|
$query = "all";
|
||||||
if ($this->opt_record_type != '') {
|
if ($this->opt_record_type != '') {
|
||||||
@@ -272,10 +270,10 @@ class searchEngine_adapter_phrasea_engine extends searchEngine_adapter_abstract
|
|||||||
|
|
||||||
$perPage = $this->get_per_page();
|
$perPage = $this->get_per_page();
|
||||||
$page = $this->get_current_page();
|
$page = $this->get_current_page();
|
||||||
$this->offset_start = $courcahnum = (($page - 1) * $perPage);
|
$this->offset_start = $courcahnum = $offset;
|
||||||
|
|
||||||
$res = phrasea_fetch_results(
|
$res = phrasea_fetch_results(
|
||||||
$session->get_ses_id(), (int) (($page - 1) * $perPage) + 1, $perPage, false
|
$session->get_ses_id(), $offset, $perPage, false
|
||||||
);
|
);
|
||||||
|
|
||||||
$rs = array();
|
$rs = array();
|
||||||
|
@@ -189,6 +189,59 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSearch_withOffset()
|
||||||
|
{
|
||||||
|
$request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||||
|
$result = $this->object->search_records($request);
|
||||||
|
$this->assertEquals(200, $result->get_http_code());
|
||||||
|
$this->assertEquals('application/json', $result->get_content_type());
|
||||||
|
$this->assertTrue(is_array(json_decode($result->format(), true)));
|
||||||
|
|
||||||
|
$data = json_decode($result->format(), true);
|
||||||
|
|
||||||
|
if ($data['response']['total_results'] < 2) {
|
||||||
|
$this->markTestSkipped('Not enough data to test');
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = $data['response']['total_results'];
|
||||||
|
|
||||||
|
$request = new Request(array(
|
||||||
|
'offset_start' => 0,
|
||||||
|
'per_page' => 1,
|
||||||
|
), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||||
|
$resultData1 = $this->object->search_records($request);
|
||||||
|
|
||||||
|
$data = json_decode($resultData1->format(), true);
|
||||||
|
|
||||||
|
$this->assertCount(1, $data['response']['results']);
|
||||||
|
$result1 = array_pop($data['response']['results']);
|
||||||
|
|
||||||
|
$request = new Request(array(
|
||||||
|
'offset_start' => 1,
|
||||||
|
'per_page' => 1,
|
||||||
|
), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||||
|
$resultData2 = $this->object->search_records($request);
|
||||||
|
|
||||||
|
$data = json_decode($resultData2->format(), true);
|
||||||
|
|
||||||
|
$this->assertCount(1, $data['response']['results']);
|
||||||
|
$result2 = array_pop($data['response']['results']);
|
||||||
|
|
||||||
|
// item at offset #0 is different than offset at item #1
|
||||||
|
$this->assertNotEquals($result1['record_id'], $result2['record_id']);
|
||||||
|
|
||||||
|
// last item is last item
|
||||||
|
$request = new Request(array(
|
||||||
|
'offset_start' => $total - 1,
|
||||||
|
'per_page' => 10,
|
||||||
|
), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json'));
|
||||||
|
$resultData = $this->object->search_records($request);
|
||||||
|
|
||||||
|
$data = json_decode($resultData->format(), true);
|
||||||
|
|
||||||
|
$this->assertCount(1, $data['response']['results']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testSearch_recordsWithStories()
|
public function testSearch_recordsWithStories()
|
||||||
{
|
{
|
||||||
$story = \record_adapter::createStory(self::$collection);
|
$story = \record_adapter::createStory(self::$collection);
|
||||||
|
Reference in New Issue
Block a user