Skip to content

Commit

Permalink
Work Area: Update Work Area - Search in results
Browse files Browse the repository at this point in the history
  • Loading branch information
BLKSerene committed Jan 5, 2025
1 parent 60b0c8e commit 87fef44
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions wordless/wl_results/wl_results_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ def find_next(self):
if self.items_found:
selected_rows = []

for table in self.tables:
table.disable_updates()

for table in self.tables:
if table.get_selected_rows():
selected_rows = [id(table), table.get_selected_rows()]
Expand Down Expand Up @@ -231,19 +228,13 @@ def find_next(self):
self.tables[0].scrollTo(table.model().index(self.items_found[0][1], 0))
self.tables[0].selectRow(self.items_found[0][1])

for table in self.tables:
table.enable_updates()

@wl_misc.log_time
def find_prev(self):
self.find_all()

if self.items_found:
selected_rows = []

for table in self.tables:
table.disable_updates()

for table in self.tables:
if table.get_selected_rows():
selected_rows = [id(table), table.get_selected_rows()]
Expand Down Expand Up @@ -276,9 +267,6 @@ def find_prev(self):
self.tables[-1].scrollTo(table.model().index(self.items_found[-1][1], 0))
self.tables[-1].selectRow(self.items_found[-1][1])

for table in self.tables:
table.enable_updates()

@wl_misc.log_time
def find_all(self):
# Search only when there are no search history or search settings have been changed
Expand Down Expand Up @@ -406,14 +394,23 @@ def run(self):

search_terms |= set(search_terms_file)

for search_term in search_terms:
len_search_term = len(search_term)
lens_search_terms = [len(search_term) for search_term in search_terms]

for (row, col), text in results.items():
matched = False

for (row, col), text in results.items():
for search_term, len_search_term in zip(search_terms, lens_search_terms):
for ngram in wl_nlp_utils.ngrams(text, len_search_term):
if ngram == tuple(search_term):
self.dialog.items_found.append([table, row, col])

matched = True

break

if matched:
break

self.dialog.items_found = sorted(
self.dialog.items_found,
key = lambda item: (id(item[0]), item[1], item[2])
Expand Down

0 comments on commit 87fef44

Please sign in to comment.