aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
Diffstat (limited to 'wqflask')
-rwxr-xr-xwqflask/wqflask/do_search.py9
-rwxr-xr-xwqflask/wqflask/search_results.py61
-rwxr-xr-xwqflask/wqflask/views.py6
3 files changed, 47 insertions, 29 deletions
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py
index 90d88a5a..6bf24faf 100755
--- a/wqflask/wqflask/do_search.py
+++ b/wqflask/wqflask/do_search.py
@@ -73,8 +73,11 @@ class DoSearch(object):
search_type_string += '_' + search_type['key']
print("search_type_string is:", search_type_string)
-
- return cls.search_types[search_type_string]
+
+ if search_type_string in cls.search_types:
+ return cls.search_types[search_type_string]
+ else:
+ return None
class QuickMrnaAssaySearch(DoSearch):
"""A general search for mRNA assays"""
@@ -613,6 +616,8 @@ class PhenotypeLrsSearch(LrsSearch, PhenotypeSearch):
return self.execute(self.query)
+
+
class CisTransLrsSearch(DoSearch):
def get_from_clause(self):
diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py
index 8d857fb4..b48c9583 100755
--- a/wqflask/wqflask/search_results.py
+++ b/wqflask/wqflask/search_results.py
@@ -77,9 +77,9 @@ class SearchResultPage(object):
self.trait_type = kw['trait_type']
self.quick_search()
else:
+ self.search_term_exists = True
self.results = []
print("kw is:", kw)
- #self.quick_search = False
self.search_terms = kw['search_terms']
if kw['type'] == "Phenotypes":
dataset_type = "Publish"
@@ -225,27 +225,35 @@ class SearchResultPage(object):
previous_from_clauses = [] #The same table can't be referenced twice in the from clause
for i, a_search in enumerate(self.search_terms):
the_search = self.get_search_ob(a_search)
- get_from_clause = getattr(the_search, "get_from_clause", None)
- if callable(get_from_clause):
- from_clause = the_search.get_from_clause()
- if from_clause in previous_from_clauses:
- pass
- else:
- previous_from_clauses.append(from_clause)
- combined_from_clause += from_clause
- where_clause = the_search.get_where_clause()
- combined_where_clause += "(" + where_clause + ")"
- if (i+1) < len(self.search_terms):
- combined_where_clause += "AND"
- final_query = the_search.compile_final_query(combined_from_clause, combined_where_clause)
- results = the_search.execute(final_query)
- self.results.extend(results)
+ if the_search != None:
+ get_from_clause = getattr(the_search, "get_from_clause", None)
+ if callable(get_from_clause):
+ from_clause = the_search.get_from_clause()
+ if from_clause in previous_from_clauses:
+ pass
+ else:
+ previous_from_clauses.append(from_clause)
+ combined_from_clause += from_clause
+ where_clause = the_search.get_where_clause()
+ combined_where_clause += "(" + where_clause + ")"
+ if (i+1) < len(self.search_terms):
+ combined_where_clause += "AND"
+ else:
+ self.search_term_exists = False
+ if self.search_term_exists:
+ final_query = the_search.compile_final_query(combined_from_clause, combined_where_clause)
+ results = the_search.execute(final_query)
+ self.results.extend(results)
else:
for a_search in self.search_terms:
the_search = self.get_search_ob(a_search)
- self.results.extend(the_search.run())
+ if the_search != None:
+ self.results.extend(the_search.run())
+ else:
+ self.search_term_exists = False
- self.header_fields = the_search.header_fields
+ if the_search != None:
+ self.header_fields = the_search.header_fields
def get_search_ob(self, a_search):
print("[kodak] item is:", pf(a_search))
@@ -258,10 +266,13 @@ class SearchResultPage(object):
print("search_type is:", pf(search_type))
search_ob = do_search.DoSearch.get_search(search_type)
- search_class = getattr(do_search, search_ob)
- print("search_class is: ", pf(search_class))
- the_search = search_class(search_term,
- search_operator,
- self.dataset,
- )
- return the_search
+ if search_ob:
+ search_class = getattr(do_search, search_ob)
+ print("search_class is: ", pf(search_class))
+ the_search = search_class(search_term,
+ search_operator,
+ self.dataset,
+ )
+ return the_search
+ else:
+ return None
diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py
index 201d1452..09bf2270 100755
--- a/wqflask/wqflask/views.py
+++ b/wqflask/wqflask/views.py
@@ -128,7 +128,7 @@ def search_page():
else:
return render_template("data_sharing.html", **template_vars.__dict__)
else:
- key = "search_results:v1:" + json.dumps(request.args, sort_keys=True)
+ key = "search_results:v2:" + json.dumps(request.args, sort_keys=True)
print("key is:", pf(key))
with Bench("Loading cache"):
result = Redis.get(key)
@@ -149,8 +149,10 @@ def search_page():
if result['quick']:
return render_template("quick_search.html", **result)
- else:
+ elif result['search_term_exists']:
return render_template("search_result_page.html", **result)
+ else:
+ return render_template("search_error.html")
@app.route("/docedit")
def docedit():