title: Speed up JSONB full text search in PostgreSQL/SQLAlchemy
body: <p>The performance of my JSONB full text search is awfully slow using PostgreSQL and SQLAlchemy. How can I speed it up?</p>
  
  <h2>Model</h2>
  
  <pre><code>class Book(Base):
      __tablename__ = "book"
      id = Column(Integer, primary_key=True)
      jsondata = Column(JSONB)
      __table_args__ = (Index('index_jsondesc',
                        text("(jsondata-&gt;'description') jsonb_path_ops"),
                        postgresql_using="gin"),)
  </code></pre>
  
  <h2>Full text search in the JSONB column</h2>
  
  <pre><code>class BookSearch:
      def __init__(self):
          pass
      def search(keyword):
          self.query = self.query.filter(Book.jsondata['description'].cast(Unicode).match(keyword))
  
  booksearch = BookSearch()
  booksearch.search("Python")
  </code></pre>