Added artist sort name filed

This commit is contained in:
emeric
2019-04-09 13:08:05 +02:00
parent 3da931e52a
commit a0e57ce2c4
3 changed files with 16 additions and 6 deletions
+11 -4
View File
@@ -31,8 +31,9 @@ namespace Database
{
Artist::Artist(const std::string& name, const std::string& MBID)
: _name{std::string(name, 0 , _maxNameLength)},
_MBID{MBID}
: _name {std::string(name, 0 , _maxNameLength)},
_sortName {_name},
_MBID {MBID}
{
}
@@ -68,7 +69,7 @@ Artist::getAll(Wt::Dbo::Session& session, boost::optional<std::size_t> offset, b
Wt::Dbo::collection<pointer> res = session.find<Artist>()
.offset(offset ? static_cast<int>(*offset) : -1)
.limit(size ? static_cast<int>(*size) : -1)
.orderBy("name COLLATE NOCASE");
.orderBy("sort_name COLLATE NOCASE");
return std::vector<pointer>(res.begin(), res.end());
}
@@ -111,7 +112,7 @@ getQuery(Wt::Dbo::Session& session,
if (!clusterIds.empty())
oss << " GROUP BY t.id HAVING COUNT(*) = " << clusterIds.size();
oss << " ORDER BY a.name COLLATE NOCASE";
oss << " ORDER BY a.sort_name COLLATE NOCASE";
Wt::Dbo::Query<Artist::pointer> query = session.query<Artist::pointer>( oss.str() );
@@ -255,4 +256,10 @@ Artist::getClusterGroups(std::vector<ClusterType::pointer> clusterTypes, std::si
return res;
}
void
Artist::setSortName(const std::string& sortName)
{
_sortName = std::string(sortName, 0 , _maxNameLength);
}
} // namespace Database
+4 -1
View File
@@ -74,7 +74,8 @@ class Artist : public Wt::Dbo::Dbo<Artist>
// size is the max number of cluster per cluster type
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
void setMBID(std::string mbid) { _MBID = mbid; }
void setMBID(const std::string& mbid) { _MBID = mbid; }
void setSortName(const std::string& sortName);
// Create
static pointer create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID = "");
@@ -84,6 +85,7 @@ class Artist : public Wt::Dbo::Dbo<Artist>
void persist(Action& a)
{
Wt::Dbo::field(a, _name, "name");
Wt::Dbo::field(a, _name, "sort_name");
Wt::Dbo::field(a, _MBID, "mbid");
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToMany, "track_artist", "", Wt::Dbo::OnDeleteCascade);
@@ -94,6 +96,7 @@ class Artist : public Wt::Dbo::Dbo<Artist>
static const std::size_t _maxNameLength = 128;
std::string _name;
std::string _sortName;
std::string _MBID; // Musicbrainz Identifier
Wt::Dbo::collection<Wt::Dbo::ptr<Track>> _tracks; // Tracks of this artist