Skip to content
Snippets Groups Projects
Commit ba01dbf0 authored by Renzo Frigato's avatar Renzo Frigato Committed by GitHub
Browse files

Merge pull request #373 from scitran/search-on-analyses

enable search for analysis
parents b2916753 aca7cbb2
No related branches found
No related tags found
No related merge requests found
......@@ -23,11 +23,12 @@ class PathNotValidException(Exception):
class PathParser:
_search_graph = {
'collections': ['sessions', 'notes', 'files'],
'collections': ['sessions', 'notes', 'files', 'analyses'],
'groups': ['projects'],
'projects': ['sessions', 'notes', 'files'],
'sessions': ['acquisitions', 'notes', 'files'],
'acquisitions': ['notes', 'files']
'projects': ['sessions', 'notes', 'files', 'analyses'],
'sessions': ['acquisitions', 'notes', 'files', 'analyses'],
'acquisitions': ['notes', 'files', 'analyses'],
'analyses': ['notes', 'files']
}
def __init__(self, path):
......
......@@ -144,6 +144,19 @@ class TargetProperty(object):
)['hits']['hits']
return {r['_id']: r for r in results}
class TargetInAnalysis(TargetProperty):
def __init__(self, name, query, analyses_query):
self.target_analysys = TargetProperty('analyses', analyses_query)
self.name = name
self.query = query
def get_results(self, parent_name, parent_results):
analysis_list = self.target_analysys.get_results(parent_name, parent_results)
return self._get_results('analyses', analysis_list)
class PreparedSearch(object):
containers = ['groups', 'projects', 'sessions', 'collections', 'acquisitions']
......@@ -163,14 +176,20 @@ class PreparedSearch(object):
def _get_targets(self, path):
path_parts = path.split('/')
query = self.queries.get(path_parts[-1])
if path_parts[-1] in ['files', 'notes']:
target = TargetProperty(path_parts[-1], query)
if len(path_parts) == 1:
if path_parts[-1] in ['files', 'notes', 'analyses']:
if len(path_parts) >= 2 and path_parts[-2] == 'analyses':
min_length = 2
analyses_query = self.queries.get('analyses')
target = TargetInAnalysis(path_parts[-1], query, analyses_query)
else:
min_length = 1
target = TargetProperty(path_parts[-1], query)
if len(path_parts) == min_length:
return {
c: [copy.deepcopy(target)] for c in self.containers
}
else:
return {path_parts[-2]: [target]}
return {path_parts[-min_length-1]: [target]}
else:
return {path_parts[-1]: [path_parts[-1]]}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment