1
0
mirror of git://jb55.com/damus synced 2024-10-04 19:00:42 +00:00

nostrdb/search: add limit param

If we only care to have a certain number of results

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2023-12-01 16:21:25 -08:00
parent bec92249f9
commit 01c239c0eb
2 changed files with 5 additions and 3 deletions

View File

@ -2567,7 +2567,7 @@ static void ndb_text_search_results_init(
} }
int ndb_text_search(struct ndb_txn *txn, const char *query, 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 buffer[1024], *buf;
unsigned char saved_buf[1024], *saved; unsigned char saved_buf[1024], *saved;
@ -2600,8 +2600,10 @@ int ndb_text_search(struct ndb_txn *txn, const char *query,
return 0; return 0;
} }
limit = min(MAX_TEXT_SEARCH_RESULTS, limit);
// for each word, we recursively find all of the submatches // 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; last_result = NULL;
result = &results->results[results->num_results]; result = &results->results[results->num_results];

View File

@ -377,7 +377,7 @@ void ndb_filter_end_field(struct ndb_filter *);
void ndb_filter_free(struct ndb_filter *filter); void ndb_filter_free(struct ndb_filter *filter);
// FULLTEXT SEARCH // 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 // stats
int ndb_stat(struct ndb *ndb, struct ndb_stat *stat); int ndb_stat(struct ndb *ndb, struct ndb_stat *stat);