Dunno anything about Org or
org-sparse-tree. But if it makes only some text visible by making the rest of the text invisible, then Isearch should automatically do the right thing: search only the visible text.
However, you might need to set (or bind, in, e.g., a command you write), option
nil. The default value is
open, which means that certain invisible text can be matched (opened) by Isearch.
C-h v search-invisible tells you:
search-invisible is a variable defined in
Its value is open
t incremental search/query-replace can match hidden text.
nil value means don't match invisible text.
When the value is
open, if the text matched is made invisible by
an overlay having an
invisible property and that overlay has a property
isearch-open-invisible, then incremental search will show the contents.
(This applies when using
To temporarily change the value for an active incremental search,
See also the related option
reveal-mode if you want overlays to automatically be opened
whenever point is in one of them.
You can customize this variable.
As that doc also says, you can use
M-s i to toggle the value temporarily.
But of course, this variable has an effect only on overlays with property
invisible and property