Merge branch 'main' into main
This commit is contained in:
commit
263c4d82b5
|
@ -5,10 +5,6 @@ release channel, you can take advantage of these new features and fixes.
|
|||
|
||||
## New Features/Changes
|
||||
|
||||
- **Improved Media Search**: We've overhauled our media search functions to add support
|
||||
for [extended search](https://www.fusejs.io/examples.html#extended-search) queries. Searches now also include values
|
||||
stored in custom fields.
|
||||
|
||||
## Code Quality/Technical Changes
|
||||
|
||||
## Bug Fixes
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
"league/mime-type-detection": "^1.7",
|
||||
"league/oauth2-client": "^2.6",
|
||||
"league/plates": "^3.1",
|
||||
"loilo/fuse": "^7.0",
|
||||
"lstrojny/fxmlrpc": "dev-master",
|
||||
"marcw/rss-writer": "^0.4.0",
|
||||
"matomo/device-detector": "^6",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1a41be64f51e4bc965bcf2f53e06bc11",
|
||||
"content-hash": "5bca0c641ba21645d05ab830394898ae",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aws/aws-crt-php",
|
||||
|
@ -3426,69 +3426,6 @@
|
|||
},
|
||||
"time": "2023-01-16T20:25:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "loilo/fuse",
|
||||
"version": "7.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/loilo/Fuse.git",
|
||||
"reference": "3304788d2f30d677faea700e0e466006f1d70015"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/loilo/Fuse/zipball/3304788d2f30d677faea700e0e466006f1d70015",
|
||||
"reference": "3304788d2f30d677faea700e0e466006f1d70015",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.4 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"dms/phpunit-arraysubset-asserts": "^0.3.0 || ^0.4.0 || ^0.5.0",
|
||||
"phpunit/phpunit": "^8.0 || ^9.0",
|
||||
"psalm/plugin-phpunit": "^0.16.1 || ^0.17.0 || ^0.18.0",
|
||||
"squizlabs/php_codesniffer": "^3.6",
|
||||
"vimeo/psalm": "^4.9 || ^5.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/Core/computeScore.php",
|
||||
"src/Core/config.php",
|
||||
"src/Core/format.php",
|
||||
"src/Core/parse.php",
|
||||
"src/Helpers/get.php",
|
||||
"src/Helpers/sort.php",
|
||||
"src/Helpers/types.php",
|
||||
"src/Search/Bitap/computeScore.php",
|
||||
"src/Search/Bitap/convertMaskToIndices.php",
|
||||
"src/Search/Bitap/createPatternAlphabet.php",
|
||||
"src/Search/Bitap/search.php",
|
||||
"src/Search/Extended/parseQuery.php",
|
||||
"src/Transform/transformMatches.php",
|
||||
"src/Transform/transformScore.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Fuse\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Florian Reuschel",
|
||||
"email": "florian@loilo.de"
|
||||
}
|
||||
],
|
||||
"description": "Fuzzy search for PHP based on Bitap algorithm",
|
||||
"support": {
|
||||
"issues": "https://github.com/loilo/Fuse/issues",
|
||||
"source": "https://github.com/loilo/Fuse/tree/v7.0.1"
|
||||
},
|
||||
"time": "2023-11-27T17:21:41+00:00"
|
||||
},
|
||||
{
|
||||
"name": "lstrojny/fxmlrpc",
|
||||
"version": "dev-master",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -64,6 +64,7 @@ export default defineConfig({
|
|||
},
|
||||
server: {
|
||||
strictPort: true,
|
||||
host: true,
|
||||
fs: {
|
||||
allow: ['..']
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ use App\Http\RouterInterface;
|
|||
use App\Http\ServerRequest;
|
||||
use App\Media\MimeType;
|
||||
use App\Paginator;
|
||||
use App\Service\FuseSearch;
|
||||
use App\Utilities\Strings;
|
||||
use App\Utilities\Types;
|
||||
use Doctrine\Common\Collections\Order;
|
||||
|
@ -37,8 +36,7 @@ final class ListAction implements SingleActionInterface
|
|||
|
||||
public function __construct(
|
||||
private readonly CacheInterface $cache,
|
||||
private readonly StationFilesystems $stationFilesystems,
|
||||
private readonly FuseSearch $fuseSearch
|
||||
private readonly StationFilesystems $stationFilesystems
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -71,12 +69,7 @@ final class ListAction implements SingleActionInterface
|
|||
];
|
||||
|
||||
if ($isSearch) {
|
||||
if ($playlist instanceof StationPlaylist) {
|
||||
$cacheKeyParts[] = 'search_playlist_' . $playlist->getIdRequired();
|
||||
}
|
||||
if (!empty($special)) {
|
||||
$cacheKeyParts[] = 'search_special_' . rawurlencode($special);
|
||||
}
|
||||
$cacheKeyParts[] = 'search_' . rawurlencode($searchPhraseFull);
|
||||
}
|
||||
|
||||
$cacheKey = implode('.', $cacheKeyParts);
|
||||
|
@ -120,7 +113,7 @@ final class ListAction implements SingleActionInterface
|
|||
)->setParameter('storageLocation', $storageLocation)
|
||||
->setParameter('path', $pathLike);
|
||||
|
||||
// Apply special searches (string searches happen below).
|
||||
// Apply searching
|
||||
if ($isSearch) {
|
||||
if ('unprocessable' === $special) {
|
||||
$mediaQueryBuilder = null;
|
||||
|
@ -154,6 +147,12 @@ final class ListAction implements SingleActionInterface
|
|||
)->setParameter('playlist', $playlist);
|
||||
}
|
||||
|
||||
if (!empty($searchPhrase)) {
|
||||
$mediaQueryBuilder->andWhere(
|
||||
'(sm.title LIKE :query OR sm.artist LIKE :query OR sm.path LIKE :query)'
|
||||
)->setParameter('query', '%' . $searchPhrase . '%');
|
||||
}
|
||||
|
||||
$unprocessableMediaRaw = [];
|
||||
}
|
||||
|
||||
|
@ -266,41 +265,11 @@ final class ListAction implements SingleActionInterface
|
|||
$this->cache->set($cacheKey, $result, 300);
|
||||
}
|
||||
|
||||
// Apply searching
|
||||
if (!empty($searchPhrase)) {
|
||||
$result = $this->fuseSearch->search(
|
||||
$searchPhrase,
|
||||
$result,
|
||||
[
|
||||
'keys' => [
|
||||
'text',
|
||||
'path',
|
||||
'album',
|
||||
'genre',
|
||||
'custom_fields',
|
||||
],
|
||||
'threshold' => 0.2,
|
||||
'useExtendedSearch' => true,
|
||||
'getFn' => fn(FileList $record, array $key) => match ($key[0] ?? null) {
|
||||
'text' => $record->media->text,
|
||||
'path' => $record->path,
|
||||
'album' => $record->media->album,
|
||||
'genre' => $record->media->genre,
|
||||
'custom_fields' => implode(' ', $record->media->custom_fields),
|
||||
default => null,
|
||||
},
|
||||
],
|
||||
$cacheKey,
|
||||
300,
|
||||
$flushCache
|
||||
);
|
||||
}
|
||||
|
||||
$propertyAccessor = self::getPropertyAccessor();
|
||||
|
||||
// Apply sorting
|
||||
[$sort, $sortOrder] = $this->getSortFromRequest($request);
|
||||
|
||||
$propertyAccessor = self::getPropertyAccessor();
|
||||
|
||||
usort(
|
||||
$result,
|
||||
static fn(FileList $a, FileList $b) => self::sortRows(
|
||||
|
|
|
@ -12,15 +12,6 @@ trait HasMediaSearch
|
|||
{
|
||||
use EntityManagerAwareTrait;
|
||||
|
||||
/**
|
||||
* @param Station $station
|
||||
* @param string $query
|
||||
* @return array{
|
||||
* string,
|
||||
* StationPlaylist|null,
|
||||
* string|null
|
||||
* }
|
||||
*/
|
||||
private function parseSearchQuery(
|
||||
Station $station,
|
||||
string $query
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use Fuse\Fuse;
|
||||
use InvalidArgumentException;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
final class FuseSearch
|
||||
{
|
||||
public const int DEFAULT_TTL = 60;
|
||||
|
||||
public function __construct(
|
||||
private readonly CacheInterface $cache,
|
||||
) {
|
||||
}
|
||||
|
||||
public function search(
|
||||
?string $searchPhrase,
|
||||
array $records,
|
||||
array $options,
|
||||
string $cacheKey,
|
||||
int $cacheTtl = self::DEFAULT_TTL,
|
||||
bool $flushCache = false
|
||||
): array {
|
||||
$fuse = $this->buildSearch($records, $options, $cacheKey, $cacheTtl, $flushCache);
|
||||
return array_column($fuse->search($searchPhrase), 'item');
|
||||
}
|
||||
|
||||
public function buildSearch(
|
||||
array $records,
|
||||
array $options,
|
||||
string $cacheKey,
|
||||
int $cacheTtl = self::DEFAULT_TTL,
|
||||
bool $flushCache = false
|
||||
): Fuse {
|
||||
$keys = $options['keys'] ?? null;
|
||||
if (null === $keys) {
|
||||
throw new InvalidArgumentException('No keys provided for search.');
|
||||
}
|
||||
|
||||
$keysHash = substr(md5(json_encode($keys, JSON_THROW_ON_ERROR)), 0, 6);
|
||||
$cacheKey .= '_fuse_' . $keysHash;
|
||||
|
||||
if (!$flushCache && $this->cache->has($cacheKey)) {
|
||||
$indexData = $this->cache->get($cacheKey);
|
||||
$index = Fuse::parseIndex(
|
||||
$indexData,
|
||||
$options
|
||||
);
|
||||
} else {
|
||||
$index = Fuse::createIndex($keys, $records, $options);
|
||||
|
||||
$this->cache->set(
|
||||
$cacheKey,
|
||||
$index->jsonSerialize(),
|
||||
$cacheTtl
|
||||
);
|
||||
}
|
||||
|
||||
return new Fuse($records, $options, $index);
|
||||
}
|
||||
}
|
|
@ -16,8 +16,12 @@ $diBuilder = AppFactory::createContainerBuilder($environment);
|
|||
|
||||
$httpFactory = new App\Http\HttpFactory();
|
||||
$worker = \Spiral\RoadRunner\Worker::create();
|
||||
|
||||
$psr7Worker = new Spiral\RoadRunner\Http\PSR7Worker($worker, $httpFactory, $httpFactory, $httpFactory);
|
||||
|
||||
// Allow for streaming larger responses back to Roadrunner.
|
||||
$psr7Worker->chunkSize = 1024 * 25;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$request = $psr7Worker->waitRequest();
|
||||
|
|
Loading…
Reference in New Issue