diff --git a/src/database/database.cpp b/src/database/database.cpp index 9d7dd057..0ed5e389 100644 --- a/src/database/database.cpp +++ b/src/database/database.cpp @@ -333,6 +333,7 @@ auto Database::GetIndexes() -> std::vector { // configurable indexes, they will need to come from somewhere. return { kAllTracks, + kAllAlbums, kAlbumsByArtist, kTracksByGenre, }; diff --git a/src/database/include/index.hpp b/src/database/include/index.hpp index 17229164..17b40f5b 100644 --- a/src/database/include/index.hpp +++ b/src/database/include/index.hpp @@ -68,5 +68,6 @@ auto ExpandHeader(const IndexKey::Header&, const std::optional&) extern const IndexInfo kAlbumsByArtist; extern const IndexInfo kTracksByGenre; extern const IndexInfo kAllTracks; +extern const IndexInfo kAllAlbums; } // namespace database diff --git a/src/database/index.cpp b/src/database/index.cpp index d480e84b..844b33a3 100644 --- a/src/database/index.cpp +++ b/src/database/index.cpp @@ -31,6 +31,12 @@ const IndexInfo kAllTracks{ .components = {Tag::kTitle}, }; +const IndexInfo kAllAlbums{ + .id = 4, + .name = "All Albums", + .components = {Tag::kAlbum, Tag::kAlbumTrack}, +}; + static auto missing_component_text(Tag tag) -> std::optional { switch (tag) { case Tag::kArtist: @@ -59,15 +65,19 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch) .track = {}, }; - std::optional value; + auto& col = std::use_facet>(std::locale()); + for (std::uint8_t i = 0; i < info.components.size(); i++) { // Fill in the text for this depth. auto text = t.tags().at(info.components.at(i)); + std::string value; if (text) { - key.item = *text; + std::string orig = *text; + key.item = col.transform(&orig[0], &orig[0] + orig.size()); + value = *text; } else { key.item = {}; - value = missing_component_text(info.components.at(i)); + value = missing_component_text(info.components.at(i)).value_or(""); } // If this is the last component, then we should also fill in the track id @@ -82,7 +92,7 @@ auto Index(const IndexInfo& info, const Track& t, leveldb::WriteBatch* batch) } auto encoded = EncodeIndexKey(key); - batch->Put(encoded.slice, value.value_or("")); + batch->Put(encoded.slice, value); // If there are more components after this, then we need to finish by // narrowing the header with the current title.