Example #1
0
    def getConnection(self, core=None):
        """ returns an existing connection or opens one """
        if not isActive():
            return None
        if core is None:
            connection_key = 'connection'
        else:
            connection_key = 'connection_{0}'.format(core)
        conn = getLocal(connection_key)
        if conn is not None:
            return conn

        zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
        registry = getUtility(IRegistry)
        config_host = registry['collective.solr.host']
        if zcmlconfig is not None:
            # use connection parameters defined in zcml...
            logger.debug('opening connection to %s', zcmlconfig.host)
            conn = SolrConnection(host=zcmlconfig.host,
                                  solrBase=zcmlconfig.base,
                                  persistent=True)
            setLocal(connection_key, conn)
        elif config_host is not None:
            # otherwise use connection parameters defined in control panel...
            config_port = registry['collective.solr.port']
            config_base = registry['collective.solr.base']
            if core is not None:
                config_base = '/'.join([config_base, core])
            config_base = config_base.rstrip('/')
            host = '%s:%d' % (config_host, config_port)
            logger.debug('opening connection to %s', host)
            conn = SolrConnection(host=host, solrBase=config_base,
                                  persistent=True)
            setLocal(connection_key, conn)
        return conn
Example #2
0
    def getConnection(self):
        """ returns an existing connection or opens one """
        if not isActive():
            return None
        conn = getLocal('connection')
        if conn is not None:
            return conn

        zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
        registry = getUtility(IRegistry)
        config_host = registry['collective.solr.host']
        if zcmlconfig is not None:
            # use connection parameters defined in zcml...
            logger.debug('opening connection to %s', zcmlconfig.host)
            conn = SolrConnection(host=zcmlconfig.host,
                                  solrBase=zcmlconfig.base,
                                  persistent=True)
            setLocal('connection', conn)
        elif config_host is not None:
            # otherwise use connection parameters defined in control panel...
            config_port = registry['collective.solr.port']
            config_base = registry['collective.solr.base']
            host = '%s:%d' % (config_host, config_port)
            logger.debug('opening connection to %s', host)
            conn = SolrConnection(host=host,
                                  solrBase=config_base,
                                  persistent=True)
            setLocal('connection', conn)
        return conn
Example #3
0
    def getConnection(self):
        """ returns an existing connection or opens one """
        if not isActive():
            return None
        conn = getLocal('connection')
        if conn is not None:
            return conn

        zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
        registry = getUtility(IRegistry)
        config_host = registry['collective.solr.host']
        if zcmlconfig is not None:
            # use connection parameters defined in zcml...
            logger.debug('opening connection to %s', zcmlconfig.host)
            conn = SolrConnection(host=zcmlconfig.host,
                                  solrBase=zcmlconfig.base,
                                  persistent=True)
            setLocal('connection', conn)
        elif config_host is not None:
            # otherwise use connection parameters defined in control panel...
            config_port = registry['collective.solr.port']
            config_base = registry['collective.solr.base']
            host = '%s:%d' % (config_host, config_port)
            logger.debug('opening connection to %s', host)
            conn = SolrConnection(host=host, solrBase=config_base,
                                  persistent=True)
            setLocal('connection', conn)
        return conn
Example #4
0
 def __call__(self, request, **keywords):
     """ decide on a search backend and perform the given query """
     if isActive():
         try:
             return solrSearchResults(request, **keywords)
         except FallBackException:
             pass
     if getattr(aq_base(self.context), '_cs_old_searchResults', None):
         return self.context._cs_old_searchResults(request, **keywords)
     return ZCatalog.searchResults(self.context, request, **keywords)
Example #5
0
 def __call__(self, request, **keywords):
     """ decide on a search backend and perform the given query """
     if isActive():
         try:
             return solrSearchResults(request, **keywords)
         except FallBackException:
             pass
     if getattr(aq_base(self.context), '_cs_old_searchResults', None):
         return self.context._cs_old_searchResults(request, **keywords)
     return ZCatalog.searchResults(self.context, request, **keywords)
Example #6
0
    def getConnection(self, core=None):
        """ returns an existing connection or opens one """
        if not isActive():
            return None
        if core is None:
            connection_key = 'connection'
        else:
            connection_key = 'connection_{0}'.format(core)
        conn = getLocal(connection_key)
        if conn is not None:
            return conn

        zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
        registry = getUtility(IRegistry)
        config_host = registry['collective.solr.host']
        if zcmlconfig is not None:
            # use connection parameters defined in zcml...
            logger.debug('opening connection to %s', zcmlconfig.host)
            conn = SolrConnection(host=zcmlconfig.host,
                                  solrBase=zcmlconfig.base,
                                  persistent=True)
            setLocal(connection_key, conn)
        elif config_host is not None:
            # otherwise use connection parameters defined in control panel...
            config_port = registry['collective.solr.port']
            config_base = registry['collective.solr.base']
            if core is not None:
                config_base = '/'.join([config_base, core])
            config_base = config_base.rstrip('/')
            host = '%s:%d' % (config_host, config_port)
            logger.debug('opening connection to %s', host)
            conn = SolrConnection(host=host,
                                  solrBase=config_base,
                                  persistent=True)
            setLocal(connection_key, conn)
        return conn