From: Not Zed Date: Sun, 7 Jan 2024 21:52:42 +0000 (+1030) Subject: Use a full table scan for search so artist can included. X-Git-Url: https://code.zedzone.au/cvs?a=commitdiff_plain;h=5c9bf4f462f92531cd5771e161c4ea163fae67b3;p=playerz Use a full table scan for search so artist can included. Remove some spew which was causing performance problems. --- diff --git a/dbindex.c b/dbindex.c index 1f0745b..28ee838 100644 --- a/dbindex.c +++ b/dbindex.c @@ -543,8 +543,6 @@ dbfile *dbfile_get(dbtxn *tx, dbindex *db, int fileid) { db->res = mdb_get(tx, db->file, &key, &data); - printf("dbfile_get(%d) = %d\n", fileid, db->res); - if (db->res == 0) { dbfile *p = calloc(1, sizeof(*p)); @@ -1878,14 +1876,14 @@ int dbfile_prev_list(dbindex *db, int listid, dbfile **fp) { #include // TODO: should run over title index instead? -int dbfile_searchx(dbindex *db, const char *pattern, dbfile **results, int maxlen) { +// TODO: use dbscan interface? +int dbfile_search(dbindex *db, const char *pattern, dbfile **results, int maxlen) { MDB_txn *tx; MDB_val key, data; MDB_cursor *cursor; int res; regex_t reg; - printf("search, pattern='%s'\n", pattern); res = regcomp(®, pattern, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (res != 0) return res; @@ -1901,7 +1899,8 @@ int dbfile_searchx(dbindex *db, const char *pattern, dbfile **results, int maxle if (db->res == 0) { dbfile *file = ez_basic_decode(DBFILE_DESC, (ez_blob *)&data); - if (regexec(®, file->title, 0, NULL, 0) == 0) { + if (regexec(®, file->title, 0, NULL, 0) == 0 + || regexec(®, file->artist, 0, NULL, 0) == 0) { file->id = *(int *)key.mv_data; results[i++] = file; } else { @@ -1915,6 +1914,8 @@ int dbfile_searchx(dbindex *db, const char *pattern, dbfile **results, int maxle regfree(®); mdb_txn_abort(tx); + printf("search, pattern='%s', n=%d\n", pattern, i); + return i; fail: @@ -1927,7 +1928,8 @@ fail: // run over title index // TODO: use multi-get on the values, so only match key (title) once per duplicate data. // TODO: use dbscan interface? -int dbfile_search(dbindex *db, const char *pattern, dbfile **results, int maxlen) { +// TODO: remove? This isn't really very useful without a full substring index. +int dbfile_searchx(dbindex *db, const char *pattern, dbfile **results, int maxlen) { MDB_txn *tx; MDB_val key, data; MDB_cursor *cursor; diff --git a/disk-util.c b/disk-util.c index a2f8c9a..215a77d 100644 --- a/disk-util.c +++ b/disk-util.c @@ -240,7 +240,7 @@ int main(int argc, char **argv) { if (res >= 0) { for (int i=0;iid, results[i]->title); + printf("%6d %-50s %s\n", results[i]->id, results[i]->artist, results[i]->title); dbfile_free(results[i]); } } else { diff --git a/http-monitor.c b/http-monitor.c index aa52d1a..de5ebbc 100644 --- a/http-monitor.c +++ b/http-monitor.c @@ -29,6 +29,8 @@ #include "player.h" +#define MAX_SEARCH_RESULTS 300 + static dbindex *db; static notify_t player; @@ -259,8 +261,8 @@ static void write_list_json(dbindex *db, struct obstack *io, int listid, int seq } static void write_search_json(dbindex *db, struct obstack *io, const char *query) { - dbfile *results[50]; - int len = dbfile_search(db, query, results, 50); + dbfile *results[MAX_SEARCH_RESULTS]; + int len = dbfile_search(db, query, results, MAX_SEARCH_RESULTS); obstack_1grow(io, '{');