# $Id$ # $URL$ import pageheader, pagefooter import searchform, resultlist, drilldown serverConfig = infra.configRoot websiteConfig = infra.configRoot logger = logging.getLogger('meresco.search') logger.debug("Starting logger") TOOMANYCLAUSES = 'TooManyClauses' def main(headers={}, arguments={}, *args, **kwargs): templatePrefix = '' if isMobile(**kwargs): templatePrefix = 'mobile.' pageHeader = pageheader.main(*args, **kwargs) pageFooter = pagefooter.main(*args, **kwargs) language = getLanguage( kwargs['Headers'] ) logger.debug('language: ' + language) displayType = arguments.get('displayType',['multiple'])[0] if displayType == 'single': singleRecord = True else: singleRecord = False query = '' httpQuery = '' # if kwargs['query']: # logger.debug('kwargs query: ' + kwargs['query']) if ('query' in (arguments)): query = arguments.get('query', [''])[0] logger.debug ( infra.prpt('arguments', 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 = [] errorString = '' # 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', default='self') # 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' try: total, recordIds = any.executeCQL(cqlAbstractSyntaxTree=parsetree, start=offset, stop=offset+10, sortBy=sortBy, sortDescending=sortDescending) docset = any.docsetFromQuery(cqlAbstractSyntaxTree=parsetree) except: tb = format_exc() logger.error(tb) if (tb.find(TOOMANYCLAUSES) != -1): errorString = websiteConfig.get(TOOMANYCLAUSES, section='userFeedback',language=language) else: results = any.getResponse(query, drilldownArguments, extra, dbserver=url, start=offset, stop=offset+10, sortBy=sortBy, sortDescending=sortDescending, infra = infra) 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) if not isPermaLink(**kwargs): searchForm = searchform.main(arguments=arguments, *args, **kwargs) messageOfTheDay = websiteConfig.get('messageOfTheDay', section = 'userFeedback', default = "goodmorning captain", language = language) bzvTitle = websiteConfig.get("applicationName", section = "userFeedback", default = "forgot it", language = language) find = websiteConfig.get("find", section = "vocabulary", default = "Find: ", language = language) booksAndArticles = websiteConfig.get("booksAndArticles", section = "vocabulary", default = "thingies", language = language) records = {} if 'records' in results: records = results['records'] resultList = resultlist.main(total=total, recordIds=recordIds, records=records, duration=duration, cqlQuery=cqlQuery, httpQuery = httpQuery, errorString=errorString, arguments=arguments, *args, **kwargs ) if isPermaLink(**kwargs): yield backtick('permaLink.template', { 'pageHeader': pageHeader, 'pageFooter': pageFooter, 'resultList': resultList, }) elif singleRecord: templateFile = templatePrefix + 'singleRecord.template' yield backtick(templateFile, { 'pageHeader': pageHeader, 'pageFooter': pageFooter, 'drilldowns': drilldowns, 'messageOfTheDay': messageOfTheDay, 'searchForm': searchForm, 'resultList': resultList, }) else: templateFile = templatePrefix + 'search.template' yield backtick(templateFile, { 'pageFooter': pageFooter, 'pageHeader': pageHeader, 'drilldowns': drilldowns, 'messageOfTheDay': messageOfTheDay, 'rssLink': rssLink, 'rssImage': rssImage, 'searchForm': searchForm, 'resultList': resultList, 'find': find, 'bzvTitle': bzvTitle, 'booksAndArticles': booksAndArticles, })