# $Id$ # $URL$ import pageheader, pagefooter import searchform, resultlist, drilldown serverConfig = configs['server'] websiteConfig = configs['website'] logger = logging.getLogger('meresco.search') logger.debug("Starting logger") TOOMANYCLAUSES = 'TooManyClauses' def main(headers={}, arguments={}, *args, **kwargs): mobileExpr = re.compile('^/m/') path = kwargs['path'] if path.startswith('/id'): permaLink = True else: permaLink = False if not mobileExpr.match(path): yield pageheader.main() 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') 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 permaLink: searchForm = searchform.main(arguments=arguments, *args, **kwargs) messageOfTheDay = websiteConfig.get('messageOfTheDay', section = 'userFeedback', default = "goodmorning captain") #bzvTitle = websiteConfig.get("applicationName", section = "userFeedback", default= "forgot it") #find = websiteConfig.get("find", section = "vocabulary", default= "Find: ") #booksAndArticles = websiteConfig.get("booksAndArticles",section= "vocabulary", default= "thingies") 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, errorString=errorString, arguments=arguments, *args, **kwargs ) if permaLink: yield backtick('permaLink.template', { 'resultList': resultList, }) elif singleRecord: yield backtick('singleRecord.template', { 'drilldowns': drilldowns, 'messageOfTheDay': messageOfTheDay, 'searchForm': searchForm, 'resultList': resultList }) else: yield backtick('search.template', { 'drilldowns': drilldowns, 'messageOfTheDay': messageOfTheDay, 'rssLink': rssLink, 'rssImage': rssImage, 'searchForm': searchForm, 'resultList': resultList }) if not mobileExpr.match(path): yield pagefooter.main()