It’s been quite a while since I wrote an AppleScript for OO, but I wrote some in the past that did row-filtering tasks that sound similar to what you’re working on.
The example below is a copy/paste of one of my scripts with the bulk pulled out and the remaining skeleton adapted to your task. It compiles and returns results that seem correct in one of my documents. YMMV, but I hope it’s helpful!
tell application "OmniOutliner"
tell front document
repeat with MyRow in (every row whose level is less than 3)
-- code that filters down to the exact rows I want goes here
end repeat
end tell
end tell
Edit: after posting, realized the goal was to search levels 1 & 2, not 3 and above. Corrected script.
FWIW, in Applescript probably you can do something like this:
tell application "OmniOutliner"
tell front document
set strQuery to "Search String"
set oRows to a reference to (rows whose level is less than 3 and name contains strQuery)
return name of oRows
end tell
end tell