import searchform, resultlist, drilldown import cqlparser, cqlwebutils def createCqlQuery(query, drilldownargs): q = cqlwebutils.parseCqlFromWeb(query) if q.isEmpty(): q.add('meresco.exists') q.add('true') q.EXACT() for fieldAndTerm in drilldownargs: field, term = drilldown.fieldAndTermSplit(fieldAndTerm) q.add(field) q.add(term) q.EXACT() q.AND() cqlQuery = str(q) return cqlQuery def main(headers={}, arguments={}, *args, **kwargs): yield searchform.main(arguments=arguments, *args, **kwargs) httpQuery = arguments.get('query', [''])[0] sortBy = sortDescending = None sortKeys = any.configuration().get('defaultSortKeys', None) if sortKeys: sortBy, ignored, sortDescending = sortKeys.split(',') sortDescending = sortDescending == '1' cqlQuery = createCqlQuery(httpQuery, arguments.get('drilldown', [])) parsetree = cqlparser.parseString(cqlQuery) t0 = time() hits = any.executeCQL(parsetree, sortBy=sortBy, sortDescending=sortDescending) duration = time() - t0 yield resultlist.main(hits, duration, cqlQuery, httpQuery, arguments=arguments, *args, **kwargs)