Text Search¶
ChatterBot’s storage adapters support text search functionality.
Text Search Example¶
def test_search_text_results_after_training(self):
"""
ChatterBot should return close matches to an input
string when filtering using the search_text parameter.
"""
self.chatbot.storage.create_many([
Statement('Example A for search.'),
Statement('Another example.'),
Statement('Example B for search.'),
Statement(text='Another statement.'),
])
results = list(self.chatbot.storage.filter(
search_text=self.chatbot.storage.tagger.get_text_index_string(
'Example A for search.'
)
))
self.assertEqual(len(results), 1)
self.assertEqual('Example A for search.', results[0].text)
Bigram Text Index¶
Bigram pairs are used for text search
In addition, the generation of the pairs ensures that there is a smaller number of possible matches based on the probability of finding two neighboring words in an existing string that match the search parameter.
For searches in larger data sets, the bigrams also reduce the number of OR
comparisons that need to occur on a database level. This will always be a
reduction of n - 1
where n
is the number of search words.