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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user