mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
71 lines
2.9 KiB
PHP
71 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class ElasticSearchQueryTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function it_uses_release_text_fields_constant_with_searchname_variants_only(): void
|
|
{
|
|
$driverSource = file_get_contents(__DIR__.'/../../app/Services/Search/Drivers/ElasticSearchDriver.php');
|
|
|
|
$this->assertIsString($driverSource);
|
|
$this->assertStringContainsString(
|
|
"private const RELEASE_TEXT_FIELDS = ['searchname^3', 'plainsearchname^2'];",
|
|
$driverSource
|
|
);
|
|
}
|
|
|
|
#[Test]
|
|
public function search_releases_filtered_uses_cross_fields_and_operator_and_for_release_text_queries(): void
|
|
{
|
|
$driverSource = file_get_contents(__DIR__.'/../../app/Services/Search/Drivers/ElasticSearchDriver.php');
|
|
|
|
$this->assertIsString($driverSource);
|
|
$methodSource = strstr($driverSource, 'public function searchReleasesFiltered');
|
|
$this->assertIsString($methodSource);
|
|
$methodSource = strstr($methodSource, 'private function buildReleaseFieldSpecificMustClauses', true);
|
|
$this->assertIsString($methodSource);
|
|
|
|
$this->assertStringContainsString("'fields' => self::RELEASE_TEXT_FIELDS", $methodSource);
|
|
$this->assertStringContainsString("'type' => 'cross_fields'", $methodSource);
|
|
$this->assertStringContainsString("'operator' => 'and'", $methodSource);
|
|
$this->assertStringNotContainsString(
|
|
"'fields' => ['searchname^3', 'name^2', 'filename', 'plainsearchname']",
|
|
$methodSource
|
|
);
|
|
$this->assertStringNotContainsString("'type' => 'best_fields'", $methodSource);
|
|
}
|
|
|
|
#[Test]
|
|
public function releases_index_search_entrypoints_use_release_text_fields_constant(): void
|
|
{
|
|
$driverSource = file_get_contents(__DIR__.'/../../app/Services/Search/Drivers/ElasticSearchDriver.php');
|
|
|
|
$this->assertIsString($driverSource);
|
|
$this->assertGreaterThanOrEqual(
|
|
3,
|
|
substr_count($driverSource, 'fields: self::RELEASE_TEXT_FIELDS'),
|
|
'Expected indexSearch/indexSearchApi/indexSearchTMA to use RELEASE_TEXT_FIELDS.'
|
|
);
|
|
}
|
|
|
|
#[Test]
|
|
public function filtered_release_search_supports_search_after_without_loading_source(): void
|
|
{
|
|
$driverSource = file_get_contents(__DIR__.'/../../app/Services/Search/Drivers/ElasticSearchDriver.php');
|
|
|
|
$this->assertIsString($driverSource);
|
|
$methodSource = strstr($driverSource, 'public function searchReleasesFiltered');
|
|
$this->assertIsString($methodSource);
|
|
$this->assertStringContainsString("\$body['search_after']", $methodSource);
|
|
$this->assertStringContainsString("'_source' => false", $methodSource);
|
|
$this->assertStringContainsString("'track_total_hits' => (bool)", $methodSource);
|
|
}
|
|
}
|