I have been looking into this issue as my first contribution to Joplin.
I could make out following in this issue :
when we create a "REST API server Joplin" using cli client by joplin --profile /joplin/profile server start,
we have started first instance/process of joplin
and later when we call "sync" command on the CLI client using joplin --profile /joplin/profile sync
it creates another instance of Joplin which is sharing the same profile.
now if we were using TUI or GUI joplin, searchengine scheduler would have rebuilt index after sometime as suggest by laurent in earlier reply quoted as follows :
The search engine would need to index the note first, and I don't think that can be triggered via CLI. You'd need to start the TUI and let it run for some time, a few seconds probably, until indexing is done
However, CLI client executing "sync" command exits before the searchengine scheduler could be triggered to reindex notes. Hence, searchengine index in "REST API server Joplin" is stale and is unable to find newly added notes in search api call
Therefore for the solution, we can call this function public async syncTables() after the sync is finished, it ensures that searchindex is refreshed. We will need to add this in Command_sync.ts present in app-cli.
Further we may not need to the handle changes made by REST API manually as these changes will be handled by searchengine scheduler running in same instance of Joplin which is receiving REST API calls unlike the changes by "sync" command made in a Joplin instance different than "REST API server Joplin".
Please comment if I have understood the problem and also if solution suggested to trigger reindexing in sync command itself makes sense in this case.