Refactor doc search class to allow single document search

This commit is contained in:
Veronica Berglyd Olsen
2024-03-28 13:40:15 +01:00
parent 821e3c4be5
commit 536e828cc6
+7 -7
View File
@@ -337,12 +337,15 @@ class DocSearch:
"""Iteratively search through documents in a project."""
self._regEx.setPattern(self._buildPattern(search))
logger.debug("Searching with pattern '%s'", self._regEx.pattern())
num = len(search)
storage = project.storage
for item in project.tree:
if item.isFileType():
text = storage.getDocumentText(item.itemHandle)
results, capped = self.searchText(storage.getDocumentText(item.itemHandle))
yield item, results, capped
return
def searchText(self, text: str) -> tuple[list[tuple[int, int, str]], bool]:
"""Search a piece of text for RegEx matches."""
rxItt = self._regEx.globalMatch(text)
count = 0
capped = False
@@ -358,10 +361,7 @@ class DocSearch:
if count >= nwConst.MAX_SEARCH_RESULT:
capped = True
break
yield item, results, capped
return
return results, capped
##
# Internal Functions