Enhance search index handling by returning an empty array for no results instead of throwing an error. Improve memory management in free_words function by checking for NULL before freeing. Update search_index to properly return NULL when no results are found.

This commit is contained in:
seb
2025-06-27 03:15:45 +02:00
parent 21f527ba46
commit 8474c77163
2 changed files with 13 additions and 5 deletions

View File

@@ -129,9 +129,9 @@ Napi::Value SearchIndexWrapper::Search(const Napi::CallbackInfo& info) {
int num_results = 0;
SearchResult* results = search_index(this->index_, query.c_str(), cutoff, &num_results);
if (!results) {
Napi::Error::New(env, "Search failed").ThrowAsJavaScriptException();
return env.Null();
// If no results found, return empty array instead of throwing error
if (!results || num_results == 0) {
return Napi::Array::New(env, 0);
}
Napi::Array result_array = Napi::Array::New(env, num_results);