diff options
author | Zachary Sloan | 2013-03-26 23:10:49 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-03-26 23:10:49 +0000 |
commit | e2ca00d32752df02214c9c249a3aab7d2e9a6ad2 (patch) | |
tree | 37eb5503b084432bf3f0e4149a3d79a868113c39 /wqflask/maintenance/quick_search_table.py | |
parent | 06367191cc7179a606c7533cead23c1de127eb13 (diff) | |
download | genenetwork2-e2ca00d32752df02214c9c249a3aab7d2e9a6ad2.tar.gz |
Continued working on quick_search_table.py, which now gets
all of the terms from the ProbeSet table to be included in
the quick search
Diffstat (limited to 'wqflask/maintenance/quick_search_table.py')
-rw-r--r-- | wqflask/maintenance/quick_search_table.py | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/wqflask/maintenance/quick_search_table.py b/wqflask/maintenance/quick_search_table.py index a337a543..51426ab2 100644 --- a/wqflask/maintenance/quick_search_table.py +++ b/wqflask/maintenance/quick_search_table.py @@ -14,7 +14,7 @@ import zach_settings as zs Engine = sa.create_engine(zs.SQLALCHEMY_DATABASE_URI, #encoding='utf-8', #client_encoding='utf-8', - echo="debug", + #echo="debug", ) Session = scoped_session(sessionmaker(bind=Engine)) #, extension=VersionedListener())) @@ -28,11 +28,48 @@ Metadata.bind = Engine class ProbeSet(Base): __tablename__ = 'ProbeSet' __table_args__ = {'autoload': True} + +#QuickSearch = sa.Table("QuickSearch", Metadata, +# sa.Column('table_name', sa.String), +# sa.Column('the_key', sa.String), +# sa.Column('terms', sa.String)) + +class QuickSearch(Base): + table_name = Column(String) + the_key = Column(String) + terms = Column(String) + + def __init__(self, table_name, the_key, terms): + self.table_name = table_name + self.the_key = the_key + self.terms = get_unique_terms(terms) + +def get_unique_terms(*args): + if not args: + return None + unique = set() + for item in args: + #print("locals:", locals()) + if not item: + continue + for token in item.split(): + if token.startswith(('(','[')): + token = token[1:] + if token.endswith((')', ']')): + token = token[:-1] + if len(token) > 2: + unique.add(token) + print("\nUnique terms are: {}\n".format(unique)) + return " ".join(unique) + def main(): for ps in page_query(Session.query(ProbeSet)): #all() - #for ps in probe_sets: - print("--->", ps) + terms = get_unique_terms(ps.Name, + ps.Symbol, + ps.description) + + def page_query(q): """http://stackoverflow.com/a/1217947/1175849""" |