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
Show file tree
Hide file tree
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
add helper utilities
  • Loading branch information
squirrelo committed Mar 16, 2015
commit ff58d42250bb2aee4022e8b78921aff8c69737c6
17 changes: 7 additions & 10 deletions qiita_db/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,13 @@ def convert_type(obj):
convert to a float. If that fails it returns the original string.
"""
item = None
if isinstance(obj, datetime):
item = str(obj)
else:
for fn in (int, float, str):
try:
item = fn(obj)
except ValueError:
continue
else:
break
for fn in (int, float, str):
try:
item = fn(obj)
except ValueError:
continue
else:
break
if item is None:
raise IncompetentQiitaDeveloperError("Can't convert item of type %s!" %
str(type(obj)))
Expand Down
43 changes: 2 additions & 41 deletions qiita_pet/handlers/analysis_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
check_access_to_analysis_result,
get_table_cols,
filepath_ids_to_rel_paths)
from qiita_db.search import QiitaStudySearch
from qiita_ware.search import search, count_metadata
from qiita_db.exceptions import (
QiitaDBIncompatibleDatatypeError, QiitaDBUnknownIDError)

Expand Down Expand Up @@ -59,37 +59,6 @@ def check_analysis_access(user, analysis):


class SearchStudiesHandler(BaseHandler):
def _parse_search_results(self, results, selsamples, meta_headers):
"""remove already selected samples from results and count metadata"""
counts = {}
fullcounts = {meta: defaultdict(int) for meta in meta_headers}
studypop = []
for study, samples in viewitems(results):
counts[study] = {meta: Counter()
for meta in meta_headers}
topop = []
for pos, sample in enumerate(samples):
if study in selsamples and sample[0] in selsamples[study]:
topop.append(pos)
# still add to full counts, but not study counts
for pos, meta in enumerate(meta_headers):
fullcounts[meta][sample[pos+1]] += 1
else:
for pos, meta in enumerate(meta_headers):
counts[study][meta][sample[pos+1]] += 1
fullcounts[meta][sample[pos+1]] += 1
# if no samples left, remove the study from results
if len(topop) == len(samples):
studypop.append(study)
continue
# remove already selected samples
topop.sort(reverse=True)
for pos in topop:
samples.pop(pos)
for study in studypop:
results.pop(study)
return results, counts, fullcounts

def _selected_parser(self, analysis):
"""builds dictionaries of selected samples from analysis object"""
selsamples = {}
Expand Down Expand Up @@ -163,12 +132,6 @@ def post(self):
analysis_id = analysis.id
# set to second step since this page is second step in workflow
analysis.step = SELECT_SAMPLES
# fill example studies by running query for specific studies
search = QiitaStudySearch()
def_query = 'study_id = 1 OR study_id = 2 OR study_id = 3'
results, meta_headers = search(def_query, user)
results, counts, fullcounts = self._parse_search_results(
results, selsamples, meta_headers)
else:
analysis_id = int(self.get_argument("analysis-id"))
analysis = Analysis(analysis_id)
Expand All @@ -177,7 +140,6 @@ def post(self):

# run through action requested
if action == "search":
search = QiitaStudySearch()
query = str(self.get_argument("query"))
try:
results, meta_headers = search(query, user)
Expand All @@ -189,8 +151,7 @@ def post(self):
if not results and not searchmsg:
searchmsg = "No results found."
else:
results, counts, fullcounts = self._parse_search_results(
results, selsamples, meta_headers)
fullcounts, counts = count_metadata(results, meta_headers)

elif action == "select":
analysis.add_samples(self._parse_form_select())
Expand Down