Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzy search pattern problem #192

Open
bruno-carvalho-everest opened this issue Oct 1, 2024 · 0 comments
Open

Fuzzy search pattern problem #192

bruno-carvalho-everest opened this issue Oct 1, 2024 · 0 comments

Comments

@bruno-carvalho-everest
Copy link

Hi,

I think there is a problem in your fuzzy search logic. In case you execute the line match = re.search(re.escape(best_match[0]), edited_content), you are not updating the pattern variable, which compiles for the exact match string, instead of the fuzzy match result. So when you do pattern.sub, I think this would fail. Did I miss something?

         # Use regex to find the content, ignoring leading/trailing whitespace
         pattern = re.compile(re.escape(search_content), re.DOTALL)
         match = pattern.search(edited_content)

         if match or (USE_FUZZY_SEARCH and similarity >= 0.8):
             if not match:
                 # If using fuzzy search and no exact match, find the best match
                 best_match = difflib.get_close_matches(search_content, [edited_content], n=1, cutoff=0.6)
                 if best_match:
                     match = re.search(re.escape(best_match[0]), edited_content)

             if match:
                 # Replace the content using re.sub for more robust replacement
                 replace_content_cleaned = re.sub(r'</?SEARCH>|</?REPLACE>', '', replace_content)
                 edited_content = pattern.sub(replace_content_cleaned, edited_content, count=1)
                 changes_made = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant