Which is the best aproach for creating a "did you mean instead" for a search with vanilla JS?

I’m using Jaccard but I’m getting really bad results, the idea is to detect errors and suggest correct and similar search keywords, I’m not sure how to improve it or if is better to use another type of function.
Here’s the working code:

const headersContainer = document.getElementById('post-content');
    const headersS = Array.from(headersContainer.querySelectorAll('h2, h3, h4, h5, h6, p, ul, pre')).map(headerS => headerS.textContent);

    const searchInputS = document.getElementById('searchbox');
    const suggestionsDiv = document.getElementById('suggestions');

    searchInputS.addEventListener('input', handleInput);

    function handleInput() {
      const userInput = searchInputS.value.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
      const suggestions = getSuggestions(userInput);

      // Display suggestions
      displaySuggestions(suggestions);
    }

    function getSuggestions(userInput) {
      const threshold = 0.5; // Adjust similarity threshold as needed
      const similarHeaders = headersS.filter(headerS => similarity(userInput, headerS.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "")) > threshold);
      return similarHeaders;
    }


    function similarity(str1, str2) {
      const len1 = str1.length;
      const len2 = str2.length;
      const maxLength = Math.max(len1, len2);

      // Calculate Jaccard similarity
      const intersection = new Set([...str1].filter(char => str2.includes(char)));
      const union = new Set([...str1, ...str2]);

      const jaccardSimilarity = intersection.size / union.size;

      // Adjust similarity based on the length of the words
      const lengthAdjustment = maxLength === 0 ? 0 : 1 - Math.abs(len1 - len2) / maxLength;

      return jaccardSimilarity * lengthAdjustment;
    }

    function displaySuggestions(suggestions) {
      // Clear previous suggestions
      suggestionsDiv.innerHTML = '';

      // Display new suggestions
      suggestions.forEach(suggestion => {
        const suggestionElement = document.createElement('div');
        suggestionElement.textContent = suggestion;
        suggestionElement.addEventListener('click', () => {
          // Set the selected suggestion as the search query
          searchInputS.value = suggestion;
          suggestionsDiv.innerHTML = ''; // Clear suggestions after selecting one
        });
        suggestionsDiv.appendChild(suggestionElement);
      });
    }