From 15d15dc065752cdbc1b5959984a9aca3235545ca Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Wed, 22 Jun 2016 16:33:10 +0000 Subject: Search: taking search apart --- doc/Architecture.org | 6 ++---- wqflask/wqflask/do_search.py | 1 + wqflask/wqflask/search_results.py | 23 ++++++++++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/doc/Architecture.org b/doc/Architecture.org index e8ffe69b..7736e2c1 100644 --- a/doc/Architecture.org +++ b/doc/Architecture.org @@ -29,8 +29,8 @@ When you hit a search with, for example, 'http://localhost:5003/search?species=mouse&group=BXD&type=Hippocampus+mRNA&dataset=HC_M2_0606_P&search_terms_or=&search_terms_and=MEAN%3D%2815+16%29+LRS%3D%2823+46%29+&FormID=searchResult' it has the menu items as parameters. According to the routing table, the search is executed and Redis caching is used (we'll probably -change that to gn_server). The logic is in search_result.py which -invokes database functions in +change that to the level of the gn_server). The logic is in +search_result.py which invokes database functions in wqflask/dbFunction/webqtlDatabaseFunction.py, for example. The receiving template lives at [[https://github.com/genenetwork/genenetwork2/blob/master/wqflask/wqflask/templates/search_result_page.html][search_result_page.html]]. @@ -43,5 +43,3 @@ from the database. To get the menu data in YAML you can do something like : curl localhost:8880/int/menu/main.json|ruby extra/json2yaml.rb (json2yaml.rb is in the gn_server repo). - - diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index 76bb15b2..7ee85929 100644 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -39,6 +39,7 @@ class DoSearch(object): """Executes query and returns results""" query = self.normalize_spaces(query) logger.debug("in do_search query is:", pf(query)) + @@ results = g.db.execute(query, no_parameters=True).fetchall() return results diff --git a/wqflask/wqflask/search_results.py b/wqflask/wqflask/search_results.py index 494e1047..1a034bdd 100644 --- a/wqflask/wqflask/search_results.py +++ b/wqflask/wqflask/search_results.py @@ -47,8 +47,11 @@ logger = getLogger(__name__ ) class SearchResultPage(object): #maxReturn = 3000 - def __init__(self, kw): + """This class gets invoked after hitting submit on the main menu (in +views.py). + + """ ########################################### # Names and IDs of group / F2 set @@ -67,9 +70,9 @@ class SearchResultPage(object): #else: self.uc_id = uuid.uuid4() - logger.debug("uc_id:", self.uc_id) + logger.debug("uc_id:", self.uc_id) # contains a unique id - logger.debug("kw is:", kw) + logger.debug("kw is:", kw) # dict containing search terms if kw['search_terms_or']: self.and_or = "or" self.search_terms = kw['search_terms_or'] @@ -78,14 +81,14 @@ class SearchResultPage(object): self.search_terms = kw['search_terms_and'] self.search_term_exists = True self.results = [] - if kw['type'] == "Phenotypes": + if kw['type'] == "Phenotypes": # split datatype on type field dataset_type = "Publish" elif kw['type'] == "Genotypes": dataset_type = "Geno" else: - dataset_type = "ProbeSet" + dataset_type = "ProbeSet" # ProbeSet is default self.dataset = create_dataset(kw['dataset'], dataset_type) - logger.debug("KEYWORD:", self.search_terms) + logger.debug("search_terms:", self.search_terms) self.search() if self.search_term_exists: self.gen_search_result() @@ -123,12 +126,16 @@ class SearchResultPage(object): # self.species_groups[item['result_fields']['species']].append( # item['result_fields']['group_name']) - def search(self): + """This function sets up the actual search query in the form of a SQL +statement and executes + + """ self.search_terms = parser.parse(self.search_terms) logger.debug("After parsing:", self.search_terms) if len(self.search_terms) > 1: + logger.debug("len(search_terms)>1") combined_from_clause = "" combined_where_clause = "" previous_from_clauses = [] #The same table can't be referenced twice in the from clause @@ -155,9 +162,11 @@ class SearchResultPage(object): if self.search_term_exists: combined_where_clause = "(" + combined_where_clause + ")" final_query = the_search.compile_final_query(combined_from_clause, combined_where_clause) + logger.debug(final_query) results = the_search.execute(final_query) self.results.extend(results) else: + logger.debug("len(search_terms)<=1") if self.search_terms == []: self.search_term_exists = False else: -- cgit v1.2.3