# $Id$ # $URL$ import searchform, resultlist, drilldown serverConfig = configs['server'] websiteConfig = configs['website'] logger = logging.getLogger('meresco.search') logger.debug("Starting logger") def main(headers={}, arguments={}, *args, **kwargs): displayType = arguments.get('displayType',['multiple'])[0] if displayType == 'single': singleRecord = True else: singleRecord = False logger.debug('displayType: ' + displayType) logger.debug('singleRecord: ' + str(singleRecord)) query = '' httpQuery = '' if kwargs['query']: logger.debug('kwargs query: ' + kwargs['query']) if ('query' in (arguments)): query = arguments.get('query', [''])[0] logger.debug ( infra.prpt('QUERY', arguments)) httpQuery = arguments.get('query', [''])[0] httpQuery = escapeHtml(httpQuery) sortBy = sortDescending = None sortKeys = arguments.get('sortKeys', [''])[0] if not sortKeys: sortKeys = any.configuration().get('defaultSortKeys', None) if sortKeys: sortBy, ignored, sortDescending = sortKeys.split(',') drilldownArguments = arguments.get('drilldown', []) extra = arguments.get('extra', []) offset = int(arguments.get('offset', ['0'])[0]) # initialisations # results = {} docset = [] total = 0 recordIds = [] # parsetree wordt doorgegeven aan search engine via de call executeCQL # cqlQuery is de serialisatie die gebruikt wordt voor RSS parsetree, cqlQuery = any.parseQuery(query, drilldownArguments, extra) url = serverConfig.get('url', section='dbserver') # De start en stop argumenten bepalen het begin en eind record welke worden teruggegeven. # De +10 in de stop is dus de batchgrootte. if query: t0 = time() if url == 'self': sortDescending = sortDescending == '1' total, recordIds = any.executeCQL(cqlAbstractSyntaxTree=parsetree, start=offset, stop=offset+10, sortBy=sortBy, sortDescending=sortDescending) docset = any.docsetFromQuery(cqlAbstractSyntaxTree=parsetree) else: results = any.getResponse(query, drilldownArguments, extra, dbserver=url, start=offset, stop=offset+10, sortBy=sortBy, sortDescending=sortDescending) total = results['total'] if 'recordIds' in results: recordIds = results['recordIds'] duration = time() - t0 else: duration = 0.000 if not singleRecord: rssLink = '%s/rss?%s' % (any.configuration().get('baseURL', ''), urlencode({'query': cqlQuery})) rssImage = '/files/' + websiteConfig.get('rss', section='images') # generator objects drilldownResults = {} if 'drilldownResults' in results: drilldownResults = results['drilldownResults'] multilevelResults = {} if 'multilevelResults' in results: multilevelResults = results['multilevelResults'] drilldowns = drilldown.main(total=total, docset=docset, drilldownResults=drilldownResults, multilevelResults=multilevelResults, arguments=arguments, *args, **kwargs) searchForm = searchform.main(arguments=arguments, *args, **kwargs) messageOfTheDay = websiteConfig.get('messageOfTheDay', section = 'userFeedback') records = {} if 'records' in results: records = results['records'] resultList = resultlist.main(total=total, recordIds=recordIds, records=records, duration=duration, cqlQuery=cqlQuery, httpQuery = httpQuery, arguments=arguments, *args, **kwargs ) if singleRecord: yield backtick('singleRecord.template', { 'messageOfTheDay': messageOfTheDay, 'resultList': resultList }) else: yield backtick('search.template', { 'drilldowns': drilldowns, 'messageOfTheDay': messageOfTheDay, 'rssLink': rssLink, 'rssImage': rssImage, 'searchForm': searchForm, 'resultList': resultList })