core/tags/artist: Convert lowercased string into tokens
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
be29f53eaa
commit
b643b532d7
|
@ -118,7 +118,7 @@ static bool __album_query_artist(struct album *album, struct artist *al_artist,
|
||||||
gchar *release, *artist, *year;
|
gchar *release, *artist, *year;
|
||||||
bool found;
|
bool found;
|
||||||
|
|
||||||
if (!al_artist || strncmp(al_artist->ar_lower, "various", 7) == 0)
|
if (!al_artist || strcmp(al_artist->ar_tokens[0], "various") == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
release = g_strdup_printf("release:\"%s\"~", lower);
|
release = g_strdup_printf("release:\"%s\"~", lower);
|
||||||
|
|
|
@ -13,7 +13,7 @@ static struct artist *__artist_alloc(gchar *name)
|
||||||
|
|
||||||
dbe_init(&artist->ar_dbe, artist);
|
dbe_init(&artist->ar_dbe, artist);
|
||||||
artist->ar_name = name;
|
artist->ar_name = name;
|
||||||
artist->ar_lower = string_lowercase(name);
|
artist->ar_tokens = g_str_tokenize_and_fold(name, NULL, &artist->ar_alts);
|
||||||
artist->ar_playlist = NULL;
|
artist->ar_playlist = NULL;
|
||||||
|
|
||||||
return artist;
|
return artist;
|
||||||
|
@ -27,7 +27,8 @@ static struct db_entry *artist_alloc(const gchar *name)
|
||||||
|
|
||||||
static void artist_free(struct db_entry *dbe)
|
static void artist_free(struct db_entry *dbe)
|
||||||
{
|
{
|
||||||
g_free(ARTIST(dbe)->ar_lower);
|
g_strfreev(ARTIST(dbe)->ar_tokens);
|
||||||
|
g_strfreev(ARTIST(dbe)->ar_alts);
|
||||||
g_free(ARTIST(dbe));
|
g_free(ARTIST(dbe));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ struct artist *artist_get(const unsigned int index)
|
||||||
|
|
||||||
int artist_compare(struct artist *lhs, struct artist *rhs)
|
int artist_compare(struct artist *lhs, struct artist *rhs)
|
||||||
{
|
{
|
||||||
return string_compare(lhs->ar_lower, rhs->ar_lower);
|
return string_compare_tokens(lhs->ar_tokens, rhs->ar_tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TESTING
|
#ifdef CONFIG_TESTING
|
||||||
|
|
|
@ -104,7 +104,11 @@ static void track_free(struct db_entry *dbe)
|
||||||
track->tr_library->li_size--;
|
track->tr_library->li_size--;
|
||||||
|
|
||||||
filter_remove(track->tr_lower, track);
|
filter_remove(track->tr_lower, track);
|
||||||
filter_remove(track->tr_artist->ar_lower, track);
|
|
||||||
|
for (i = 0; track->tr_artist->ar_tokens[i]; i++)
|
||||||
|
filter_remove(track->tr_artist->ar_tokens[i], track);
|
||||||
|
for (i = 0; track->tr_artist->ar_alts[i]; i++)
|
||||||
|
filter_remove(track->tr_artist->ar_alts[i], track);
|
||||||
|
|
||||||
for (i = 0; track->tr_album->al_tokens[i]; i++)
|
for (i = 0; track->tr_album->al_tokens[i]; i++)
|
||||||
filter_remove(track->tr_album->al_tokens[i], track);
|
filter_remove(track->tr_album->al_tokens[i], track);
|
||||||
|
@ -122,7 +126,11 @@ static void track_setup(struct db_entry *dbe)
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
filter_add(track->tr_lower, track);
|
filter_add(track->tr_lower, track);
|
||||||
filter_add(track->tr_artist->ar_lower, track);
|
|
||||||
|
for (i = 0; track->tr_artist->ar_tokens[i]; i++)
|
||||||
|
filter_add(track->tr_artist->ar_tokens[i], track);
|
||||||
|
for (i = 0; track->tr_artist->ar_alts[i]; i++)
|
||||||
|
filter_add(track->tr_artist->ar_alts[i], track);
|
||||||
|
|
||||||
for (i = 0; track->tr_album->al_tokens[i]; i++)
|
for (i = 0; track->tr_album->al_tokens[i]; i++)
|
||||||
filter_add(track->tr_album->al_tokens[i], track);
|
filter_add(track->tr_album->al_tokens[i], track);
|
||||||
|
|
|
@ -16,9 +16,10 @@
|
||||||
#include <core/database.h>
|
#include <core/database.h>
|
||||||
|
|
||||||
struct artist {
|
struct artist {
|
||||||
gchar *ar_name; /* This artist's name. */
|
gchar *ar_name; /* This artist's name. */
|
||||||
gchar *ar_lower; /* This artist's name (lowercased). */
|
gchar **ar_tokens; /* This artist's tokenized strings. */
|
||||||
void *ar_playlist; /* This artist's associated playlist. */
|
gchar **ar_alts; /* This artist's alternate ascii tokens. */
|
||||||
|
void *ar_playlist; /* This artist's associated playlist. */
|
||||||
struct db_entry ar_dbe;
|
struct db_entry ar_dbe;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ static void test_verify_empty(struct artist *artist)
|
||||||
{
|
{
|
||||||
const struct db_ops *artist_ops = test_artist_ops();
|
const struct db_ops *artist_ops = test_artist_ops();
|
||||||
test_equal(artist->ar_name, "");
|
test_equal(artist->ar_name, "");
|
||||||
test_equal(artist->ar_lower, "");
|
test_equal((void *)artist->ar_tokens[0], NULL);
|
||||||
|
test_equal((void *)artist->ar_alts[0], NULL);
|
||||||
test_equal(artist->ar_playlist, NULL);
|
test_equal(artist->ar_playlist, NULL);
|
||||||
test_equal(artist_ops->dbe_key(&artist->ar_dbe), "");
|
test_equal(artist_ops->dbe_key(&artist->ar_dbe), "");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +18,10 @@ static void test_verify_koji(struct artist *artist)
|
||||||
{
|
{
|
||||||
const struct db_ops *artist_ops = test_artist_ops();
|
const struct db_ops *artist_ops = test_artist_ops();
|
||||||
test_equal(artist->ar_name, "Koji Kondo");
|
test_equal(artist->ar_name, "Koji Kondo");
|
||||||
test_equal(artist->ar_lower, "koji kondo");
|
test_equal(artist->ar_tokens[0], "koji");
|
||||||
|
test_equal(artist->ar_tokens[1], "kondo");
|
||||||
|
test_equal((void *)artist->ar_tokens[2], NULL);
|
||||||
|
test_equal((void *)artist->ar_alts[0], NULL);
|
||||||
test_equal(artist->ar_playlist, NULL);
|
test_equal(artist->ar_playlist, NULL);
|
||||||
test_equal(artist_ops->dbe_key(&artist->ar_dbe), "Koji Kondo");
|
test_equal(artist_ops->dbe_key(&artist->ar_dbe), "Koji Kondo");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue