I would like to add a custom search attribute to the columns in the sqlalchemy model. The goal is to retrieve data only for these columns (using ModelFoo .__ table __. Columns) and put the data in solr. Is there a way to mark some columns using a custom attribute?
class ModelFoo(AppBase):
__tablename__ = 'foo'
id = Column("id", Integer, primary_key=True, autoincrement=True)
os = Column(String, nullable=False, searchable=True)
platform = Column(String, searchable=True)
By default, I get the following error when I try to do the following:
sqlalchemy.exc.ArgumentError: Unknown arguments passed to Column: ['searchable']
I am looking for a general way to add only search columns in solr, something like these lines:
for table in Base.metadata.tables.values():
keys = [str(key) for key in table.columns if key.searchable]
solr.add(session.query(*keys).all())
in the code above, I am looking for a short solution or an alternative for working with "key.searchable". Hope this clarifies the issue.
source
share