Library search upgrades: tag search, tag cloud, status filter
Backend: - MediaItem gains search_tags (custom + e621 tags, lowercase) and has_custom_data, maintained on save with a data migration backfill - File list search accepts search_type=filename|tags|both (tag search is word-AND across the flattened tag text) and status=matched|custom| unknown filters - New /api/tags/cloud/ endpoint (cached 2 min per guest/auth, invalidated on item changes and deletions) returning the most-used tags, honouring guest visibility Frontend: - Library sidebar: Filename/Tags/Both selector, status pill toggles (persisted), and a clickable tag cloud that runs a tag search - Roadmap updated
This commit is contained in:
+43
@@ -0,0 +1,43 @@
|
||||
# Generated by Django 6.1.1 on 2026-09-17 18:04
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def backfill_derived_fields(apps, schema_editor):
|
||||
MediaItem = apps.get_model("library", "MediaItem")
|
||||
for item in MediaItem.objects.all().iterator(chunk_size=200):
|
||||
names = [str(tag) for tag in (item.tags or [])]
|
||||
data = item.e621_data if isinstance(item.e621_data, dict) else {}
|
||||
categories = data.get("tags")
|
||||
if isinstance(categories, dict):
|
||||
for values in categories.values():
|
||||
if isinstance(values, list):
|
||||
names.extend(str(tag) for tag in values)
|
||||
search_tags = " ".join(
|
||||
sorted({str(name).strip().lower() for name in names if str(name).strip()})
|
||||
)
|
||||
MediaItem.objects.filter(pk=item.pk).update(
|
||||
search_tags=search_tags,
|
||||
has_custom_data=bool(item.tags or item.notes),
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('library', '0007_tempupload_visual_matches'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='mediaitem',
|
||||
name='has_custom_data',
|
||||
field=models.BooleanField(db_index=True, default=False),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='mediaitem',
|
||||
name='search_tags',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.RunPython(backfill_derived_fields, migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user