Logo
stable
  • Installation
  • Quick Start Guide
  • ChatterBot Tutorial
  • Examples
  • Training
  • Preprocessors
  • Logic Adapters
  • Storage Adapters
    • Text Search
      • Text Search Example
      • Bigram Text Index
    • Creating a new storage adapter
    • Common storage adapter attributes
    • SQL Storage Adapter
    • MongoDB Storage Adapter
    • Database Migrations
  • Filters
  • ChatterBot
  • Conversations
  • Comparisons
  • Utility Methods
  • ChatterBot Corpus
  • Django Integration
  • Frequently Asked Questions
  • Command line tools
  • Development
  • Glossary
ChatterBot
  • Docs »
  • Storage Adapters »
  • Text Search
  • Edit on GitHub

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_bigram_pair_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.

ChatterBot bigram generation process
Next Previous

© Copyright 2021, Gunther Cox Revision 181c69f2.

Ask a question under the
chatterbot tag
Report an issue on
GitHub

Subscribe to the ChatterBot Newsletter

Read the Docs v: stable
Versions
latest
stable
0.8.7
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.