Skip to content

Add FTS-backed search (songs/albums/artists) and DB migration#842

Open
theovilardo wants to merge 3 commits intocodex/create-optim.md-for-app-optimization-analysisfrom
codex/prioritize-optimization-tasks-from-optim.md
Open

Add FTS-backed search (songs/albums/artists) and DB migration#842
theovilardo wants to merge 3 commits intocodex/create-optim.md-for-app-optimization-analysisfrom
codex/prioritize-optimization-tasks-from-optim.md

Conversation

@theovilardo
Copy link
Owner

Motivation

  • Replace costly LIKE '%query%' full-table scans with an indexed full-text search to reduce CPU and latency for searches, following the optimization plan in OPTIM.md.
  • Provide prefix matching and tokenization suitable for multilingual metadata to improve perceived responsiveness on large libraries.
  • Ensure a seamless upgrade path by adding a database migration that builds the FTS tables and keeps schema versioning consistent.

Description

  • Add Room FTS entities (SongFtsEntity, AlbumFtsEntity, ArtistFtsEntity) in SearchFtsEntities.kt to model FTS tables for songs, albums and artists.
  • Bump database version to 12 and add MIGRATION_11_12 in PixelPlayDatabase.kt which creates songs_fts, albums_fts, and artists_fts virtual tables and triggers a rebuild.
  • Replace LIKE queries with FTS MATCH queries in MusicDao.kt and join the base tables with the FTS virtual tables for search results.
  • Update MusicRepositoryImpl.kt to build safe prefix FTS queries via buildFtsQuery(rawQuery) and pass the generated FTS query to the DAO, and register the new migration in AppModule.kt.

Testing

  • No automated tests or builds were executed as part of this change.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5cf8f0ba18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +97 to +101
db.execSQL("""
CREATE VIRTUAL TABLE IF NOT EXISTS songs_fts
USING fts4(
title,
artist_name,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add FTS sync triggers for migrated databases

The migration creates external-content FTS tables (content='songs', etc.) but does not create any triggers or other update path to keep the FTS index in sync after the one-time rebuild. For users upgrading from v11, any subsequent inserts/updates/deletes to songs/albums/artists will not update the FTS tables, so search results will silently miss new or modified items. To avoid stale search results, add the standard FTS4 content-table triggers in this migration (or switch to a Room migration that generates them).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments