diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c index 277d1811..8428d558 100644 --- a/nostrdb/nostrdb.c +++ b/nostrdb/nostrdb.c @@ -2567,7 +2567,7 @@ static void ndb_text_search_results_init( } int ndb_text_search(struct ndb_txn *txn, const char *query, - struct ndb_text_search_results *results) + struct ndb_text_search_results *results, int limit) { unsigned char buffer[1024], *buf; unsigned char saved_buf[1024], *saved; @@ -2600,8 +2600,10 @@ int ndb_text_search(struct ndb_txn *txn, const char *query, return 0; } + limit = min(MAX_TEXT_SEARCH_RESULTS, limit); + // for each word, we recursively find all of the submatches - while (results->num_results < MAX_TEXT_SEARCH_RESULTS) { + while (results->num_results < limit) { last_result = NULL; result = &results->results[results->num_results]; diff --git a/nostrdb/nostrdb.h b/nostrdb/nostrdb.h index 9b4c0ff9..ee0a51a5 100644 --- a/nostrdb/nostrdb.h +++ b/nostrdb/nostrdb.h @@ -377,7 +377,7 @@ void ndb_filter_end_field(struct ndb_filter *); void ndb_filter_free(struct ndb_filter *filter); // FULLTEXT SEARCH -int ndb_text_search(struct ndb_txn *txn, const char *query, struct ndb_text_search_results *); +int ndb_text_search(struct ndb_txn *txn, const char *query, struct ndb_text_search_results *, int limit); // stats int ndb_stat(struct ndb *ndb, struct ndb_stat *stat);