def _fuzzySearch(self, content, is_continue, step): encoding = lfEval("&encoding") is_ascii = False if self._cli.isRefinement: if self._cli.pattern[1] == '': # e.g. abc; if is_fuzzyMatch_C and isAscii(self._cli.pattern[0]): is_ascii = True pattern = fuzzyMatchC.initPattern(self._cli.pattern[0]) getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=True) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=True) else: fuzzy_match = FuzzyMatch(self._cli.pattern[0], encoding) getWeight = fuzzy_match.getWeight getHighlights = fuzzy_match.getHighlights filter_method = partial(self._fuzzyFilter, False, getWeight) highlight_method = partial(self._highlight, False, getHighlights) elif self._cli.pattern[0] == '': # e.g. ;abc if is_fuzzyMatch_C and isAscii(self._cli.pattern[1]): is_ascii = True pattern = fuzzyMatchC.initPattern(self._cli.pattern[1]) getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=False) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=False) else: fuzzy_match = FuzzyMatch(self._cli.pattern[1], encoding) getWeight = fuzzy_match.getWeight getHighlights = fuzzy_match.getHighlights filter_method = partial(self._fuzzyFilter, True, getWeight) highlight_method = partial(self._highlight, True, getHighlights) else: if is_fuzzyMatch_C and isAscii(self._cli.pattern[0]): is_ascii_0 = True pattern_0 = fuzzyMatchC.initPattern(self._cli.pattern[0]) getWeight_0 = partial(fuzzyMatchC.getWeight, pattern=pattern_0, is_name_only=True) getHighlights_0 = partial(fuzzyMatchC.getHighlights, pattern=pattern_0, is_name_only=True) else: is_ascii_0 = False fuzzy_match_0 = FuzzyMatch(self._cli.pattern[0], encoding) getWeight_0 = fuzzy_match_0.getWeight getHighlights_0 = fuzzy_match_0.getHighlights if is_fuzzyMatch_C and isAscii(self._cli.pattern[1]): is_ascii_1 = True pattern_1 = fuzzyMatchC.initPattern(self._cli.pattern[1]) getWeight_1 = partial(fuzzyMatchC.getWeight, pattern=pattern_1, is_name_only=False) getHighlights_1 = partial(fuzzyMatchC.getHighlights, pattern=pattern_1, is_name_only=False) else: is_ascii_1 = False fuzzy_match_1 = FuzzyMatch(self._cli.pattern[1], encoding) getWeight_1 = fuzzy_match_1.getWeight getHighlights_1 = fuzzy_match_1.getHighlights is_ascii = is_ascii_0 and is_ascii_1 filter_method = partial(self._refineFilter, getWeight_0, getWeight_1) highlight_method = partial(self._highlightRefine, getHighlights_0, getHighlights_1) else: if is_fuzzyMatch_C and isAscii(self._cli.pattern): is_ascii = True pattern = fuzzyMatchC.initPattern(self._cli.pattern) if self._getExplorer().getStlCategory( ) == "File" and self._cli.isFullPath: getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=False) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=False) else: getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=True) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=True) filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, getWeight) highlight_method = partial(self._highlight, self._cli.isFullPath, getHighlights) else: fuzzy_match = FuzzyMatch(self._cli.pattern, encoding) if self._getExplorer().getStlCategory( ) == "File" and self._cli.isFullPath: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight2) elif self._getExplorer().getStlCategory() in [ "Self", "Buffer", "Mru", "BufTag", "Function", "History", "Cmd_History", "Search_History" ]: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight3) else: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight) highlight_method = partial(self._highlight, self._cli.isFullPath, fuzzy_match.getHighlights) if step == 30000: if is_fuzzyMatch_C and is_ascii: step = 35000 elif self._getExplorer().supportsNameOnly( ) and self._cli.isFullPath: step = 5000 pairs = self._filter(step, filter_method, content, is_continue) pairs.sort(key=operator.itemgetter(0), reverse=True) self._getInstance().setBuffer(self._getList(pairs)) highlight_method()
def _fuzzySearch(self, content, is_continue, step): encoding = lfEval("&encoding") use_fuzzy_engine = False use_fuzzy_match_c = False if self._cli.isRefinement: if self._cli.pattern[0] == '': # e.g. ;abc if self._fuzzy_engine and isAscii(self._cli.pattern[1]): use_fuzzy_engine = True return_index = True pattern = fuzzyEngine.initPattern(self._cli.pattern[1]) filter_method = partial(fuzzyEngine.fuzzyMatchEx, engine=self._fuzzy_engine, pattern=pattern, is_name_only=False, sort_results=not is_continue) getHighlights = partial(fuzzyEngine.getHighlights, engine=self._fuzzy_engine, pattern=pattern, is_name_only=False) highlight_method = partial(self._highlight, True, getHighlights, True) elif is_fuzzyMatch_C and isAscii(self._cli.pattern[1]): use_fuzzy_match_c = True pattern = fuzzyMatchC.initPattern(self._cli.pattern[1]) getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=False) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=False) filter_method = partial(self._fuzzyFilter, True, getWeight) highlight_method = partial(self._highlight, True, getHighlights) else: fuzzy_match = FuzzyMatch(self._cli.pattern[1], encoding) getWeight = fuzzy_match.getWeight getHighlights = fuzzy_match.getHighlights filter_method = partial(self._fuzzyFilter, True, getWeight) highlight_method = partial(self._highlight, True, getHighlights) else: # e.g. abc;def if is_fuzzyMatch_C and isAscii(self._cli.pattern[0]): is_ascii_0 = True pattern_0 = fuzzyMatchC.initPattern(self._cli.pattern[0]) getWeight_0 = partial(fuzzyMatchC.getWeight, pattern=pattern_0, is_name_only=True) getHighlights_0 = partial(fuzzyMatchC.getHighlights, pattern=pattern_0, is_name_only=True) else: is_ascii_0 = False fuzzy_match_0 = FuzzyMatch(self._cli.pattern[0], encoding) getWeight_0 = fuzzy_match_0.getWeight getHighlights_0 = fuzzy_match_0.getHighlights if is_fuzzyMatch_C and isAscii(self._cli.pattern[1]): is_ascii_1 = True pattern_1 = fuzzyMatchC.initPattern(self._cli.pattern[1]) getWeight_1 = partial(fuzzyMatchC.getWeight, pattern=pattern_1, is_name_only=False) getHighlights_1 = partial(fuzzyMatchC.getHighlights, pattern=pattern_1, is_name_only=False) else: is_ascii_1 = False fuzzy_match_1 = FuzzyMatch(self._cli.pattern[1], encoding) getWeight_1 = fuzzy_match_1.getWeight getHighlights_1 = fuzzy_match_1.getHighlights use_fuzzy_match_c = is_ascii_0 and is_ascii_1 filter_method = partial(self._refineFilter, getWeight_0, getWeight_1) highlight_method = partial(self._highlightRefine, getHighlights_0, getHighlights_1) else: if self._fuzzy_engine and isAscii(self._cli.pattern): use_fuzzy_engine = True pattern = fuzzyEngine.initPattern(self._cli.pattern) if self._getExplorer().getStlCategory() == "File" and self._cli.isFullPath: return_index = False filter_method = partial(fuzzyEngine.fuzzyMatch, engine=self._fuzzy_engine, pattern=pattern, is_name_only=False, sort_results=not is_continue) elif self._getExplorer().getStlCategory() in ["Self", "Buffer", "Mru", "BufTag", "Function", "History", "Cmd_History", "Search_History"]: return_index = True filter_method = partial(fuzzyEngine.fuzzyMatchEx, engine=self._fuzzy_engine, pattern=pattern, is_name_only=True, sort_results=not is_continue) else: return_index = True filter_method = partial(fuzzyEngine.fuzzyMatchEx, engine=self._fuzzy_engine, pattern=pattern, is_name_only=not self._cli.isFullPath, sort_results=not is_continue) getHighlights = partial(fuzzyEngine.getHighlights, engine=self._fuzzy_engine, pattern=pattern, is_name_only=not self._cli.isFullPath) highlight_method = partial(self._highlight, self._cli.isFullPath, getHighlights, True) elif is_fuzzyMatch_C and isAscii(self._cli.pattern): use_fuzzy_match_c = True pattern = fuzzyMatchC.initPattern(self._cli.pattern) if self._getExplorer().getStlCategory() == "File" and self._cli.isFullPath: getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=False) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=False) else: getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=True) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=True) filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, getWeight) highlight_method = partial(self._highlight, self._cli.isFullPath, getHighlights) else: fuzzy_match = FuzzyMatch(self._cli.pattern, encoding) if self._getExplorer().getStlCategory() == "File" and self._cli.isFullPath: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight2) elif self._getExplorer().getStlCategory() in ["Self", "Buffer", "Mru", "BufTag", "Function", "History", "Cmd_History", "Search_History"]: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight3) else: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight) highlight_method = partial(self._highlight, self._cli.isFullPath, fuzzy_match.getHighlights) if use_fuzzy_engine: if return_index == True: step = 20000 * cpu_count else: step = 40000 * cpu_count pair = self._filter(step, filter_method, content, is_continue, True, return_index) if is_continue: # result is not sorted pairs = sorted(zip(*pair), key=operator.itemgetter(0), reverse=True) self._result_content = self._getList(pairs) else: self._result_content = pair[1] self._getInstance().setBuffer(self._result_content[:self._getInstance().window.height + 100]) self._getInstance().setStlResultsCount(len(self._result_content)) else: if step == 40000: if use_fuzzy_match_c: step = 40000 elif self._getExplorer().supportsNameOnly() and self._cli.isFullPath: step = 6000 else: step = 12000 pairs = self._filter(step, filter_method, content, is_continue) pairs.sort(key=operator.itemgetter(0), reverse=True) self._result_content = self._getList(pairs) self._getInstance().setBuffer(self._result_content[:self._getInstance().window.height + 100]) self._getInstance().setStlResultsCount(len(self._result_content)) highlight_method()
def _fuzzySearch(self, content, is_continue, step): encoding = lfEval("&encoding") is_ascii = False if self._cli.isRefinement: if self._cli.pattern[1] == '': # e.g. abc; if is_fuzzyMatch_C and isAscii(self._cli.pattern[0]): is_ascii = True pattern = fuzzyMatchC.initPattern(self._cli.pattern[0]) getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=True) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=True) else: fuzzy_match = FuzzyMatch(self._cli.pattern[0], encoding) getWeight = fuzzy_match.getWeight getHighlights = fuzzy_match.getHighlights filter_method = partial(self._fuzzyFilter, False, getWeight) highlight_method = partial(self._highlight, False, getHighlights) elif self._cli.pattern[0] == '': # e.g. ;abc if is_fuzzyMatch_C and isAscii(self._cli.pattern[1]): is_ascii = True pattern = fuzzyMatchC.initPattern(self._cli.pattern[1]) getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=False) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=False) else: fuzzy_match = FuzzyMatch(self._cli.pattern[1], encoding) getWeight = fuzzy_match.getWeight getHighlights = fuzzy_match.getHighlights filter_method = partial(self._fuzzyFilter, True, getWeight) highlight_method = partial(self._highlight, True, getHighlights) else: if is_fuzzyMatch_C and isAscii(self._cli.pattern[0]): is_ascii_0 = True pattern_0 = fuzzyMatchC.initPattern(self._cli.pattern[0]) getWeight_0 = partial(fuzzyMatchC.getWeight, pattern=pattern_0, is_name_only=True) getHighlights_0 = partial(fuzzyMatchC.getHighlights, pattern=pattern_0, is_name_only=True) else: is_ascii_0 = False fuzzy_match_0 = FuzzyMatch(self._cli.pattern[0], encoding) getWeight_0 = fuzzy_match_0.getWeight getHighlights_0 = fuzzy_match_0.getHighlights if is_fuzzyMatch_C and isAscii(self._cli.pattern[1]): is_ascii_1 = True pattern_1 = fuzzyMatchC.initPattern(self._cli.pattern[1]) getWeight_1 = partial(fuzzyMatchC.getWeight, pattern=pattern_1, is_name_only=False) getHighlights_1 = partial(fuzzyMatchC.getHighlights, pattern=pattern_1, is_name_only=False) else: is_ascii_1 = False fuzzy_match_1 = FuzzyMatch(self._cli.pattern[1], encoding) getWeight_1 = fuzzy_match_1.getWeight getHighlights_1 = fuzzy_match_1.getHighlights is_ascii = is_ascii_0 and is_ascii_1 filter_method = partial(self._refineFilter, getWeight_0, getWeight_1) highlight_method = partial(self._highlightRefine, getHighlights_0, getHighlights_1) else: if is_fuzzyMatch_C and isAscii(self._cli.pattern): is_ascii = True pattern = fuzzyMatchC.initPattern(self._cli.pattern) if self._getExplorer().getStlCategory() == "File" and self._cli.isFullPath: getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=False) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=False) else: getWeight = partial(fuzzyMatchC.getWeight, pattern=pattern, is_name_only=True) getHighlights = partial(fuzzyMatchC.getHighlights, pattern=pattern, is_name_only=True) filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, getWeight) highlight_method = partial(self._highlight, self._cli.isFullPath, getHighlights) else: fuzzy_match = FuzzyMatch(self._cli.pattern, encoding) if self._getExplorer().getStlCategory() == "File" and self._cli.isFullPath: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight2) elif self._getExplorer().getStlCategory() in ["Self", "Buffer", "Mru", "BufTag", "Function", "History", "Cmd_History", "Search_History"]: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight3) else: filter_method = partial(self._fuzzyFilter, self._cli.isFullPath, fuzzy_match.getWeight) highlight_method = partial(self._highlight, self._cli.isFullPath, fuzzy_match.getHighlights) if step == 30000: if is_fuzzyMatch_C and is_ascii: step = 35000 elif self._getExplorer().isFilePath() and self._cli.isFullPath: step = 5000 pairs = self._filter(step, filter_method, content, is_continue) pairs.sort(key=operator.itemgetter(0), reverse=True) self._getInstance().setBuffer(self._getList(pairs)) highlight_method()