Skip to content

Start improving search #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bit of rearrangement
  • Loading branch information
squirrelo committed Mar 17, 2015
commit ae6dd10b5b22539636895d0296a361b3054fe0e2
18 changes: 7 additions & 11 deletions qiita_db/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,10 @@ def __call__(self, searchstr, user, study=None):
raise ParseException('Can not search over string and '
'integer/float for same field!')

dyn_headers = meta_headers - self.req_samp_cols - self.study_cols - \
self.prep_info_cols

# remove metadata headers that come from non-dynamic tables
# get the list of dynamic table columns for sample + prep templates
conn_handler = SQLConnectionHandler()
sql = """SELECT DISTINCT column_name FROM qiita.study_sample_columns"""
sample_headers = meta_headers.intersection(
c[0] for c in conn_handler.execute_fetchall(sql))
dyn_headers = meta_headers - self.req_samp_cols - self.study_cols - \
self.prep_info_cols

if study:
sql = ["%d" % study.id]
Expand All @@ -227,8 +222,10 @@ def __call__(self, searchstr, user, study=None):
if user.level == 'user':
# trim to accessable studies
sql.append("SELECT study_id FROM qiita.study_users WHERE "
"email = '{0}' UNION SELECT study_id FROM qiita.study WHERE email = '{0}' OR"
" study_status_id = {1}".format(user.id, convert_to_id('public', 'study_status')))
"email = '{0}' UNION SELECT study_id "
"FROM qiita.study WHERE email = '{0}' OR"
" study_status_id = {1}".format(
user.id, convert_to_id('public', 'study_status')))
if sql:
st_sql = " WHERE srd.study_id in (%s)" % ' INTERSECT '.join(sql)
else:
Expand All @@ -238,8 +235,8 @@ def __call__(self, searchstr, user, study=None):
"ORDER BY srd.study_id) FROM qiita.study_raw_data srd "
"JOIN qiita.prep_template pt USING (raw_data_id)%s "
"GROUP BY study_id" % st_sql)
conn_handler = SQLConnectionHandler()
studies = conn_handler.execute_fetchall(sql)
print studies

if not studies:
# No studies found, so no need to continue
Expand Down Expand Up @@ -273,7 +270,6 @@ def __call__(self, searchstr, user, study=None):

conn_handler.add_to_queue('search', ' '.join(sql).format(
','.join(header_info)))
print 'search', ' '.join(sql).format(','.join(header_info))
results = self._process_to_dict(conn_handler.execute_queue('search'),
len(header_info))
return results, meta_headers
Expand Down