ajuste na pesquisa de informacao, para passar a dar prioridade
This commit is contained in:
@@ -56,4 +56,29 @@ final class SearchTermsTest extends TestCase
|
||||
$this->assertGreaterThan($search->score('Como investir', 'investir', ['investir']), $search->score('Investir', 'investir', ['investir']));
|
||||
$this->assertSame(['de'], $search->tokens('de'));
|
||||
}
|
||||
|
||||
public function test_direct_titles_precede_titles_and_descriptions_that_reference_the_query(): void
|
||||
{
|
||||
$search = new SearchTerms;
|
||||
$phrase = 'corredor da beira';
|
||||
$tokens = $search->tokens($phrase);
|
||||
$titles = ['Açúcar no Corredor da Beira', 'Corredor da Beira e investimentos', 'Corredor da Beira', 'Produção de açúcar'];
|
||||
usort($titles, fn ($a, $b) => $search->score($b, $phrase, $tokens) <=> $search->score($a, $phrase, $tokens));
|
||||
|
||||
$this->assertSame(['Corredor da Beira', 'Corredor da Beira e investimentos', 'Açúcar no Corredor da Beira', 'Produção de açúcar'], $titles);
|
||||
$this->assertSame($search->score('Corredor da Beira', $phrase, $tokens), $search->score('CORREDOR DA BEIRA', $phrase, $tokens));
|
||||
}
|
||||
|
||||
public function test_database_relevance_uses_the_same_levels_and_escaped_prefix(): void
|
||||
{
|
||||
$connection = new PostgresConnection(fn () => throw new \LogicException('A database must not be opened.'));
|
||||
$query = $connection->table('records');
|
||||
$search = new SearchTerms;
|
||||
$search->orderByRelevance($query, 'title', '100% açúcar', $search->tokens('100% açúcar'), 'id');
|
||||
|
||||
$this->assertStringContainsString('THEN 1000', $query->toSql());
|
||||
$this->assertStringContainsString('THEN 600', $query->toSql());
|
||||
$this->assertStringContainsString('THEN 400', $query->toSql());
|
||||
$this->assertSame(['100% acucar', '100!% acucar%', '%100!% acucar%'], array_slice($query->getBindings(), 0, 3));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user