damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 01c239c0ebb4548fffce89235fdfe7fc3494bf6d
parent bec92249f92b7e95a1a4f5d4105936ac6361b4ce
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  1 Dec 2023 16:21:25 -0800

nostrdb/search: add limit param

If we only care to have a certain number of results

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mnostrdb/nostrdb.c | 6++++--
Mnostrdb/nostrdb.h | 2+-
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git 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 @@ -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);