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));
#include <regex.h>
// 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;
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 {
regfree(®);
mdb_txn_abort(tx);
+ printf("search, pattern='%s', n=%d\n", pattern, i);
+
return i;
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;
#include "player.h"
+#define MAX_SEARCH_RESULTS 300
+
static dbindex *db;
static notify_t player;
}
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, '{');