mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 02:01:33 +00:00
Improve searches
This commit is contained in:
@@ -531,6 +531,22 @@ class ManticoreSearchDriver implements SearchDriverInterface
|
||||
return trim($result);
|
||||
}
|
||||
|
||||
private static function scopePreparedQueryToField(string $preparedQuery, string $fieldSelector = ''): string
|
||||
{
|
||||
$preparedQuery = trim($preparedQuery);
|
||||
if ($preparedQuery === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$scopedQuery = '('.$preparedQuery.')';
|
||||
|
||||
if ($fieldSelector === '') {
|
||||
return $scopedQuery;
|
||||
}
|
||||
|
||||
return $fieldSelector.' '.$scopedQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a search query contains negation operators (! or - prefix on words).
|
||||
*
|
||||
@@ -1223,7 +1239,7 @@ class ManticoreSearchDriver implements SearchDriverInterface
|
||||
if (! empty($value)) {
|
||||
$preparedValue = self::prepareUserSearchQuery($value);
|
||||
if (! empty($preparedValue)) {
|
||||
$terms[] = '@@relaxed @'.$key.' '.$preparedValue;
|
||||
$terms[] = '@@relaxed '.self::scopePreparedQueryToField($preparedValue, '@'.$key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1255,7 +1271,7 @@ class ManticoreSearchDriver implements SearchDriverInterface
|
||||
}
|
||||
}
|
||||
|
||||
$searchExpr = '@@relaxed '.$searchColumns.' '.$preparedSearch;
|
||||
$searchExpr = '@@relaxed '.self::scopePreparedQueryToField($preparedSearch, $searchColumns);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -123,6 +123,26 @@ class ManticoreSearchQueryTest extends TestCase
|
||||
$this->assertSame($expected, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function it_scopes_multi_word_queries_to_the_requested_field(): void
|
||||
{
|
||||
$reflection = new ReflectionClass(ManticoreSearchDriver::class);
|
||||
$method = $reflection->getMethod('scopePreparedQueryToField');
|
||||
|
||||
$this->assertSame(
|
||||
'@searchname (Resurrection 2025)',
|
||||
$method->invoke(null, 'Resurrection 2025', '@searchname')
|
||||
);
|
||||
$this->assertSame(
|
||||
'@(searchname,plainsearchname) (Resurrection 2025)',
|
||||
$method->invoke(null, 'Resurrection 2025', '@(searchname,plainsearchname)')
|
||||
);
|
||||
$this->assertSame(
|
||||
'(Resurrection 2025)',
|
||||
$method->invoke(null, 'Resurrection 2025')
|
||||
);
|
||||
}
|
||||
|
||||
public static function edgeCaseQueriesProvider(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user