mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
feat: improve search query (mainly theme) (#1126)
This commit is contained in:
@@ -7,7 +7,6 @@ namespace App\Filament\RelationManagers\User;
|
||||
use App\Filament\RelationManagers\BaseRelationManager;
|
||||
use App\Filament\Resources\BaseResource;
|
||||
use App\Filament\Resources\User\Submission\SubmissionStageResource;
|
||||
use App\Models\User\Submission\SubmissionStage;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
abstract class SubmissionStageRelationManager extends BaseRelationManager
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace App\Filament\RelationManagers\Wiki\Anime;
|
||||
use App\Filament\RelationManagers\BaseRelationManager;
|
||||
use App\Filament\Resources\BaseResource;
|
||||
use App\Filament\Resources\Wiki\Anime\ThemeResource;
|
||||
use App\Models\Wiki\Anime\AnimeTheme;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
abstract class ThemeRelationManager extends BaseRelationManager
|
||||
|
||||
@@ -167,7 +167,7 @@ class Anime extends BaseModel implements Auditable, HasImages, HasResources, Has
|
||||
public function toSearchableArray(): array
|
||||
{
|
||||
$array = $this->attributesToArray();
|
||||
$array['synonyms'] = $this->synonyms->toArray();
|
||||
$array['synonyms'] = $this->synonyms->map(fn (Synonym $synonym) => $synonym->text)->all();
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class EntryQuery extends ElasticQuery
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.5 * 0.85,
|
||||
'should' => $this->createNestedTextQuery('theme.anime.synonyms', 'text', $criteria->getTerm()),
|
||||
'should' => $this->createNestedTextQuery('theme.anime', 'synonyms', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -59,7 +59,6 @@ class EntryQuery extends ElasticQuery
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.85,
|
||||
'should' => $this->createTextQuery('anime_slug', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -43,16 +43,32 @@ class ThemeQuery extends ElasticQuery
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.9 * 0.85,
|
||||
'should' => $this->createNestedTextQuery('anime.synonyms', 'text', $criteria->getTerm()),
|
||||
'should' => $this->createNestedTextQuery('anime', 'synonyms', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.85,
|
||||
'should' => $this->createTextQuery('slug', $criteria->getTerm()),
|
||||
'dis_max' => [
|
||||
'queries' => [
|
||||
[
|
||||
'bool' => [
|
||||
'should' => $this->createTextQuery('slug', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'should' => $this->createTextQuery('anime_slug', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.7,
|
||||
'should' => $this->createTextQuery('synonym_slug', $criteria->getTerm()),
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -28,7 +28,7 @@ class AnimeQuery extends ElasticQuery
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.85,
|
||||
'should' => $this->createNestedTextQuery('synonyms', 'text', $criteria->getTerm()),
|
||||
'should' => $this->createTextQuery('synonyms', 'text'),
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -26,10 +26,7 @@ class SeriesQuery extends ElasticQuery
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.6,
|
||||
'should' => $this->createNestedQuery(
|
||||
'anime',
|
||||
$this->createNestedTextQuery('anime.synonyms', 'text', $criteria->getTerm())
|
||||
),
|
||||
'should' => $this->createNestedTextQuery('anime', 'synonyms', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -60,14 +60,14 @@ class VideoQuery extends ElasticQuery
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.5,
|
||||
'boost' => 0.8,
|
||||
'should' => $this->createNestedTextQuery('entries.theme.anime', 'name', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
[
|
||||
'bool' => [
|
||||
'boost' => 0.5 * 0.85,
|
||||
'should' => $this->createNestedTextQuery('entries.theme.anime.synonyms', 'text', $criteria->getTerm()),
|
||||
'boost' => 0.8 * 0.85,
|
||||
'should' => $this->createNestedTextQuery('entries.theme.anime', 'synonyms', $criteria->getTerm()),
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -39,30 +39,12 @@ final class CreateAnimeIndex implements MigrationInterface
|
||||
],
|
||||
],
|
||||
]);
|
||||
$mapping->nested('synonyms', [
|
||||
'properties' => [
|
||||
'synonymable_type' => [
|
||||
$mapping->text('synonyms', [
|
||||
'analyzer' => 'name_search',
|
||||
'fields' => [
|
||||
'keyword' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
'synonymable_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'created_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
'synonym_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'text' => [
|
||||
'type' => 'text',
|
||||
'analyzer' => 'name_search',
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'updated_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$mapping->text('synopsis', [
|
||||
|
||||
@@ -62,34 +62,6 @@ final class CreateEntryIndex implements MigrationInterface
|
||||
'slug' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'nested',
|
||||
'properties' => [
|
||||
'synonymable_type' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
'synonymable_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'created_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
'synonym_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'text' => [
|
||||
'type' => 'text',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'analyzer' => 'name_search',
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'updated_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
],
|
||||
],
|
||||
'synopsis' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
@@ -99,6 +71,16 @@ final class CreateEntryIndex implements MigrationInterface
|
||||
'year' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'text',
|
||||
'analyzer' => 'name_search',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'fields' => [
|
||||
'keyword' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'anime_id' => [
|
||||
|
||||
@@ -57,34 +57,6 @@ final class CreateSeriesIndex implements MigrationInterface
|
||||
'slug' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'nested',
|
||||
'properties' => [
|
||||
'synonymable_type' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
'synonymable_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'created_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
'synonym_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'text' => [
|
||||
'type' => 'text',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'analyzer' => 'name_search',
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'updated_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
],
|
||||
],
|
||||
'synopsis' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
@@ -94,10 +66,18 @@ final class CreateSeriesIndex implements MigrationInterface
|
||||
'year' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'text',
|
||||
'analyzer' => 'name_search',
|
||||
'fields' => [
|
||||
'keyword' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$mapping->text('anime_slug');
|
||||
$mapping->text('synonym_slug');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,34 +39,6 @@ final class CreateThemeIndex implements MigrationInterface
|
||||
'slug' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'nested',
|
||||
'properties' => [
|
||||
'synonymable_type' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
'synonymable_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'created_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
'synonym_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'text' => [
|
||||
'type' => 'text',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'analyzer' => 'name_search',
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'updated_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
],
|
||||
],
|
||||
'synopsis' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
@@ -76,6 +48,16 @@ final class CreateThemeIndex implements MigrationInterface
|
||||
'year' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'text',
|
||||
'analyzer' => 'name_search',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'fields' => [
|
||||
'keyword' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$mapping->long('anime_id');
|
||||
|
||||
@@ -73,34 +73,6 @@ final class CreateVideoIndex implements MigrationInterface
|
||||
'slug' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'nested',
|
||||
'properties' => [
|
||||
'synonymable_type' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
'synonymable_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'created_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
'synonym_id' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'text' => [
|
||||
'type' => 'text',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'analyzer' => 'name_search',
|
||||
],
|
||||
'type' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'updated_at' => [
|
||||
'type' => 'date',
|
||||
],
|
||||
],
|
||||
],
|
||||
'synopsis' => [
|
||||
'type' => 'text',
|
||||
],
|
||||
@@ -110,6 +82,16 @@ final class CreateVideoIndex implements MigrationInterface
|
||||
'year' => [
|
||||
'type' => 'long',
|
||||
],
|
||||
'synonyms' => [
|
||||
'type' => 'text',
|
||||
'analyzer' => 'name_search',
|
||||
'copy_to' => ['synonym_slug'],
|
||||
'fields' => [
|
||||
'keyword' => [
|
||||
'type' => 'keyword',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'anime_id' => [
|
||||
|
||||
Reference in New Issue
Block a user