Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-26141: Search appears to conduct some form of 'OR' search not and 'AND' search #1770

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 85 additions & 0 deletions eZ/Publish/API/Repository/Tests/SearchServiceTest.php
Expand Up @@ -4325,6 +4325,91 @@ public function testLanguageAnalysisSameContentNotFound()
$this->assertEquals(0, $searchResult->totalCount);
}

/**
* Test for the findContent() method.
*
* @see \eZ\Publish\API\Repository\SearchService::findContent()
*/
public function testFulltextComplex()
{
$repository = $this->getRepository();
$contentService = $repository->getContentService();
$contentTypeService = $repository->getContentTypeService();
$locationService = $repository->getLocationService();
$searchService = $repository->getSearchService();

$contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');

$contentCreateStruct->setField('name', 'red');
$contentCreateStruct->setField('short_name', 'red apple');
$content1 = $contentService->publishVersion(
$contentService->createContent(
$contentCreateStruct,
[$locationService->newLocationCreateStruct(2)]
)->versionInfo
);

$contentCreateStruct->setField('name', 'apple');
$contentCreateStruct->setField('short_name', 'two');
$content2 = $contentService->publishVersion(
$contentService->createContent(
$contentCreateStruct,
[$locationService->newLocationCreateStruct(2)]
)->versionInfo
);

$contentCreateStruct->setField('name', 'red apple');
$contentCreateStruct->setField('short_name', 'three');
$content3 = $contentService->publishVersion(
$contentService->createContent(
$contentCreateStruct,
[$locationService->newLocationCreateStruct(2)]
)->versionInfo
);

$this->refreshSearch($repository);

$query = new Query(
[
'query' => new Criterion\FullText(
'red apple',
[
'boost' => [
'short_name' => 2,
],
'fuzziness' => .1,
]
),
]
);

$searchResult = $searchService->findContent($query, ['languages' => ['eng-GB']]);

$this->assertEquals(3, $searchResult->totalCount);

// Legacy search engine does have scoring, sorting the results by ID in that case
$setupFactory = $this->getSetupFactory();
if (get_class($setupFactory) === 'eZ\Publish\API\Repository\Tests\SetupFactory\Legacy') {
usort(
$searchResult->searchHits,
function ($a, $b) {
return ($a->valueObject->id < $b->valueObject->id) ? -1 : 1;
}
);

$this->assertEquals($content1->id, $searchResult->searchHits[0]->valueObject->id);
$this->assertEquals($content2->id, $searchResult->searchHits[1]->valueObject->id);
$this->assertEquals($content3->id, $searchResult->searchHits[2]->valueObject->id);

return;
}

$this->assertEquals($content1->id, $searchResult->searchHits[0]->valueObject->id);
$this->assertEquals($content3->id, $searchResult->searchHits[1]->valueObject->id);
$this->assertEquals($content2->id, $searchResult->searchHits[2]->valueObject->id);
}

/**
* Assert that query result matches the given fixture.
*
Expand Down
Expand Up @@ -97,7 +97,7 @@ protected function getCondition(Criterion $criterion)
// Might make sense to use percentage in addition
'minimum_should_match' => 1,
// Default is OR, changed per FullText criterion spec
'default_operator' => 'AND',
'default_operator' => 'OR',
),
);

Expand Down