From 87fef44584e7ae842c37b3d7212e09c4c7ff298d Mon Sep 17 00:00:00 2001 From: BLKSerene Date: Sun, 5 Jan 2025 12:47:53 +0800 Subject: [PATCH] Work Area: Update Work Area - Search in results --- wordless/wl_results/wl_results_search.py | 27 +++++++++++------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/wordless/wl_results/wl_results_search.py b/wordless/wl_results/wl_results_search.py index f6e484c16..5af22290d 100644 --- a/wordless/wl_results/wl_results_search.py +++ b/wordless/wl_results/wl_results_search.py @@ -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()] @@ -231,9 +228,6 @@ 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() @@ -241,9 +235,6 @@ def find_prev(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()] @@ -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 @@ -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])