|
@@ 4412-4452 (lines=41) @@
|
| 4409 |
|
* |
| 4410 |
|
* @param array $data |
| 4411 |
|
*/ |
| 4412 |
|
public function testFulltextContentSearchComplex(array $data) |
| 4413 |
|
{ |
| 4414 |
|
// Do not initialize from scratch |
| 4415 |
|
$repository = $this->getRepository(false); |
| 4416 |
|
$searchService = $repository->getSearchService(); |
| 4417 |
|
list($criterion, $content1, $content2, $content3) = $data; |
| 4418 |
|
|
| 4419 |
|
$searchResult = $searchService->findContent( |
| 4420 |
|
new Query(['query' => $criterion]), |
| 4421 |
|
['languages' => ['eng-GB']] |
| 4422 |
|
); |
| 4423 |
|
$searchHits = $searchResult->searchHits; |
| 4424 |
|
|
| 4425 |
|
$this->assertEquals(3, $searchResult->totalCount); |
| 4426 |
|
|
| 4427 |
|
// Legacy search engine does have scoring, sorting the results by ID in that case |
| 4428 |
|
$setupFactory = $this->getSetupFactory(); |
| 4429 |
|
if (get_class($setupFactory) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy') { |
| 4430 |
|
usort( |
| 4431 |
|
$searchHits, |
| 4432 |
|
function ($a, $b) { |
| 4433 |
|
return ($a->valueObject->id < $b->valueObject->id) ? -1 : 1; |
| 4434 |
|
} |
| 4435 |
|
); |
| 4436 |
|
|
| 4437 |
|
$this->assertEquals($content1->id, $searchHits[0]->valueObject->id); |
| 4438 |
|
$this->assertEquals($content2->id, $searchHits[1]->valueObject->id); |
| 4439 |
|
$this->assertEquals($content3->id, $searchHits[2]->valueObject->id); |
| 4440 |
|
|
| 4441 |
|
return; |
| 4442 |
|
} |
| 4443 |
|
|
| 4444 |
|
// Assert scores are descending |
| 4445 |
|
$this->assertGreaterThan($searchHits[1]->score, $searchHits[0]->score); |
| 4446 |
|
$this->assertGreaterThan($searchHits[2]->score, $searchHits[1]->score); |
| 4447 |
|
|
| 4448 |
|
// Assert order |
| 4449 |
|
$this->assertEquals($content1->id, $searchHits[0]->valueObject->id); |
| 4450 |
|
$this->assertEquals($content3->id, $searchHits[1]->valueObject->id); |
| 4451 |
|
$this->assertEquals($content2->id, $searchHits[2]->valueObject->id); |
| 4452 |
|
} |
| 4453 |
|
|
| 4454 |
|
/** |
| 4455 |
|
* Test for the findLocations() method. |
|
@@ 4462-4502 (lines=41) @@
|
| 4459 |
|
* |
| 4460 |
|
* @param array $data |
| 4461 |
|
*/ |
| 4462 |
|
public function testFulltextLocationSearchComplex(array $data) |
| 4463 |
|
{ |
| 4464 |
|
// Do not initialize from scratch |
| 4465 |
|
$repository = $this->getRepository(false); |
| 4466 |
|
list($criterion, $content1, $content2, $content3) = $data; |
| 4467 |
|
$searchService = $repository->getSearchService(); |
| 4468 |
|
|
| 4469 |
|
$searchResult = $searchService->findLocations( |
| 4470 |
|
new LocationQuery(['query' => $criterion]), |
| 4471 |
|
['languages' => ['eng-GB']] |
| 4472 |
|
); |
| 4473 |
|
$searchHits = $searchResult->searchHits; |
| 4474 |
|
|
| 4475 |
|
$this->assertEquals(3, $searchResult->totalCount); |
| 4476 |
|
|
| 4477 |
|
// Legacy search engine does have scoring, sorting the results by ID in that case |
| 4478 |
|
$setupFactory = $this->getSetupFactory(); |
| 4479 |
|
if (get_class($setupFactory) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy') { |
| 4480 |
|
usort( |
| 4481 |
|
$searchHits, |
| 4482 |
|
function ($a, $b) { |
| 4483 |
|
return ($a->valueObject->id < $b->valueObject->id) ? -1 : 1; |
| 4484 |
|
} |
| 4485 |
|
); |
| 4486 |
|
|
| 4487 |
|
$this->assertEquals($content1->id, $searchHits[0]->valueObject->contentId); |
| 4488 |
|
$this->assertEquals($content2->id, $searchHits[1]->valueObject->contentId); |
| 4489 |
|
$this->assertEquals($content3->id, $searchHits[2]->valueObject->contentId); |
| 4490 |
|
|
| 4491 |
|
return; |
| 4492 |
|
} |
| 4493 |
|
|
| 4494 |
|
// Assert scores are descending |
| 4495 |
|
$this->assertGreaterThan($searchHits[1]->score, $searchHits[0]->score); |
| 4496 |
|
$this->assertGreaterThan($searchHits[2]->score, $searchHits[1]->score); |
| 4497 |
|
|
| 4498 |
|
// Assert order |
| 4499 |
|
$this->assertEquals($content1->id, $searchHits[0]->valueObject->contentId); |
| 4500 |
|
$this->assertEquals($content3->id, $searchHits[1]->valueObject->contentId); |
| 4501 |
|
$this->assertEquals($content2->id, $searchHits[2]->valueObject->contentId); |
| 4502 |
|
} |
| 4503 |
|
|
| 4504 |
|
/** |
| 4505 |
|
* Assert that query result matches the given fixture. |