port of accurate search in python
kudos to https://github.com/florin-dumitrescu/accurate-search
You can use this class in a similar way to the JavaScript
# Test the AccurateSearch class
search = AccurateSearch()
# Add some movies
movies = ['The Lighthouse', 'Marriage Story', 'The Irishman', 'Parasite', 'Little Women']
for i, movie in enumerate(movies):
search.add_text(i, movie)
# Test search
assert search.search('the') == [0, 2], "Search for 'the' failed"
assert search.search('woman') == [4], "Search for 'woman' failed"
# Test suggestions
assert search.suggestions('ma', 2) == ['marriage'], "Suggestions for 'ma' failed"
# Test remove
search.remove(2)
assert search.search('the') == [0], "Remove and search for 'the' failed"
print("All tests passed!")