Refactor doc search class to allow single document search
This commit is contained in:
@@ -337,12 +337,15 @@ class DocSearch:
|
|||||||
"""Iteratively search through documents in a project."""
|
"""Iteratively search through documents in a project."""
|
||||||
self._regEx.setPattern(self._buildPattern(search))
|
self._regEx.setPattern(self._buildPattern(search))
|
||||||
logger.debug("Searching with pattern '%s'", self._regEx.pattern())
|
logger.debug("Searching with pattern '%s'", self._regEx.pattern())
|
||||||
|
|
||||||
num = len(search)
|
|
||||||
storage = project.storage
|
storage = project.storage
|
||||||
for item in project.tree:
|
for item in project.tree:
|
||||||
if item.isFileType():
|
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)
|
rxItt = self._regEx.globalMatch(text)
|
||||||
count = 0
|
count = 0
|
||||||
capped = False
|
capped = False
|
||||||
@@ -358,10 +361,7 @@ class DocSearch:
|
|||||||
if count >= nwConst.MAX_SEARCH_RESULT:
|
if count >= nwConst.MAX_SEARCH_RESULT:
|
||||||
capped = True
|
capped = True
|
||||||
break
|
break
|
||||||
|
return results, capped
|
||||||
yield item, results, capped
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
|
|||||||
Reference in New Issue
Block a user