vomebook commited on
Commit ·
23a4455
1
Parent(s): 65b11be
Accelerate boundary wildcard search
Browse filesFiles changed (5)
6 unmodified lines7891011126 unmodified linesif "*" not in query and "?" not in query:lower = query.lower()return lambda text: lower in text.lower()# Bitset NFA: each bit is a pattern position. Collapse adjacent stars so# epsilon closure needs one shift. No input can cause regex backtracking.pattern = re.sub(r"\*+", "*", query)6 unmodified lines7891011121314151617186 unmodified linesif "*" not in query and "?" not in query:lower = query.lower()return lambda text: lower in text.lower()# In substring matching, stars at either boundary can match zero chars.# Keep Unicode IGNORECASE behavior, unlike the literal .lower() branch.core = query.strip("*")if core and "*" not in core and "?" not in core:literal = re.compile(re.escape(core), re.IGNORECASE)return lambda text: literal.search(text) is not None# Bitset NFA: each bit is a pattern position. Collapse adjacent stars so# epsilon closure needs one shift. No input can cause regex backtracking.pattern = re.sub(r"\*+", "*", query)
1234567{"tool": "mutmut 3.8.1","source": "scripts/check_search_words_mutation.py","source_sha256": "04e96d44443db60b4d50d0bae41d5ec0d6ac2d389c0c5a78259bfebbe938d305","scope": "Only ordinary built-in dicts with built-in string keys and integer values, without concurrent mutation, dict subclasses, tracing, introspection, or monkeypatching. Comparison is the return value and exceptions of mutation_errors. The initial required-field validation is executed unchanged. These survivors remain survivors, not killed.","equivalent": {"scripts.check_search_words_mutation.x_mutation_errors__mutmut_22": {1234567{"tool": "mutmut 3.8.1","source": "scripts/check_search_words_mutation.py","source_sha256": "a7ad103f8bbaa411e9ed45930058304e5cb91cf5780a6d956289a2eceb4b8db6","scope": "Only ordinary built-in dicts with built-in string keys and integer values, without concurrent mutation, dict subclasses, tracing, introspection, or monkeypatching. Comparison is the return value and exceptions of mutation_errors. The initial required-field validation is executed unchanged. These survivors remain survivors, not killed.","equivalent": {"scripts.check_search_words_mutation.x_mutation_errors__mutmut_22": {
12345678910{"tool": "mutmut 3.8.1","source": "backend/search_matching.py","source_sha256": "3869dca4057d86a7f7176e53c968f7f6bff19d5fd76977ae961b64dcde5a8843","equivalent": {"backend.search_matching.x_compile_exact_matcher__mutmut_91": {"sha256": "88464ddfa3e5fcc94b5681a967aee983093b6eb490e57b1a5e7cef7ec16fd1a9","rationale": "When wildcard is false the changed conditional value is ORed with 1 immediately afterwards; 0 | 1 and 1 | 1 both equal 1. When wildcard is true the changed branch is not evaluated."},"backend.search_matching.x_is_fuzzy_match__mutmut_7": {12345678910{"tool": "mutmut 3.8.1","source": "backend/search_matching.py","source_sha256": "528ddf36278ba56e31f4a35a8cf2c4c02a9086e234ad8e8cb82e677f9fafb0f6","equivalent": {"backend.search_matching.x_compile_exact_matcher__mutmut_109": {"sha256": "82cd836e2e189d603a8681880a15585cd5e01a078ab496a7cbc9aa446afc252d","rationale": "When wildcard is false the changed conditional value is ORed with 1 immediately afterwards; 0 | 1 and 1 | 1 both equal 1. When wildcard is true the changed branch is not evaluated."},"backend.search_matching.x_is_fuzzy_match__mutmut_7": {
27 unmodified lines28293031323327 unmodified lines"test_matching_helpers_keep_wildcard_results_after_large_character_cache","test_fuzzy_precheck_and_distance_are_bounded","test_exact_and_wildcard_matchers_keep_unicode_and_newline_semantics","test_wildcards_agree_with_independent_regular_expression_reference","test_fuzzy_helpers_match_independent_distance_and_multiset_references","test_wildcard_cache_keeps_repeated_characters_and_clears_at_limit",27 unmodified lines282930313233343527 unmodified lines"test_matching_helpers_keep_wildcard_results_after_large_character_cache","test_fuzzy_precheck_and_distance_are_bounded","test_exact_and_wildcard_matchers_keep_unicode_and_newline_semantics","test_boundary_stars_preserve_case_newlines_and_literal_metacharacters","test_boundary_stars_use_one_literal_scan_and_complex_patterns_keep_nfa","test_wildcards_agree_with_independent_regular_expression_reference","test_fuzzy_helpers_match_independent_distance_and_multiset_references","test_wildcard_cache_keeps_repeated_characters_and_clears_at_limit",
149 unmodified lines150151152153154155149 unmodified linesself.assertFalse(compile_exact_matcher("a*c")("a\nc"))self.assertTrue(compile_exact_matcher("İ*")("i-page"))def test_wildcards_agree_with_independent_regular_expression_reference(self):import itertoolsimport re149 unmodified lines150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197149 unmodified linesself.assertFalse(compile_exact_matcher("a*c")("a\nc"))self.assertTrue(compile_exact_matcher("İ*")("i-page"))def test_boundary_stars_preserve_case_newlines_and_literal_metacharacters(self):from backend.search_matching import compile_exact_matcherfor pattern in ('a*', '*a', '*a*', '**a***'):with self.subTest(pattern=pattern):self.assertTrue(compile_exact_matcher(pattern)('x\nA\ny'))self.assertFalse(compile_exact_matcher(pattern)('xyz'))for pattern in ('*', '**', '*****'):self.assertTrue(compile_exact_matcher(pattern)(''))self.assertTrue(compile_exact_matcher(pattern)('\n'))for char in ('İ', 'ı', 'ſ', 'K'):self.assertTrue(compile_exact_matcher('*' + char + '*')({'İ':'i', 'ı':'I', 'ſ':'s', 'K':'k'}[char]))self.assertTrue(compile_exact_matcher('*[.\\]*')('x[.\\]y'))self.assertFalse(compile_exact_matcher('*[.\\]*')('xyz'))self.assertFalse(compile_exact_matcher('*ab*')('a\nb'))self.assertFalse(compile_exact_matcher('a*b')('a\nb'))self.assertTrue(compile_exact_matcher('a?b')('aXb'))self.assertTrue(compile_exact_matcher('*X*')('X'))self.assertFalse(compile_exact_matcher('*X*')(''))# Escaped literal scans cannot introduce wildcard regex backtracking.self.assertFalse(compile_exact_matcher('*' + 'a' * 127 + 'b*')('a' * 20000))def test_boundary_stars_use_one_literal_scan_and_complex_patterns_keep_nfa(self):from backend import search_matchingoriginal = search_matching.re.compilecalls = []def compile_counted(expression, flags):calls.append((expression, flags))return original(expression, flags)with patch.object(search_matching.re, 'compile', side_effect=compile_counted):matcher = search_matching.compile_exact_matcher('**a.b**')self.assertEqual(calls, [(r'a\.b', search_matching.re.IGNORECASE)])self.assertTrue(matcher('A.B'))calls.clear()search_matching.compile_exact_matcher('*X*')self.assertEqual(calls, [('X', search_matching.re.IGNORECASE)])calls.clear()search_matching.compile_exact_matcher('*Xa*')self.assertEqual(calls, [('Xa', search_matching.re.IGNORECASE)])calls.clear()search_matching.compile_exact_matcher('a*b')self.assertEqual(len(calls), 2)def test_wildcards_agree_with_independent_regular_expression_reference(self):import itertoolsimport re
backend/search_matching.py+6
mutation-equivalent-mutation-gate.json+1-1
mutation-equivalent-search-matching.json+3-3
scripts/check_search_words_mutation.py+2
tests/test_search_words_contract.py+42