示例#1
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
示例#2
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
    def getConnection(self):
        """ returns an existing connection or opens one """
        config = getUtility(ISolrConnectionConfig)
        if not config.active:
            return None
        conn = getLocal('connection')
        if conn is not None:
            return conn

        zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
        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...
            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
示例#4
0
    def getConnection(self):
        """ returns an existing connection or opens one """
        config = getUtility(ISolrConnectionConfig)
        if not config.active:
            return None
        conn = getLocal('connection')
        if conn is not None:
            return conn

        zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
        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...
            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
示例#5
0
文件: manager.py 项目: jean/ftw.solr
    def getConnection(self):
        """ returns an existing connection or opens one """
        config = getUtility(ISolrConnectionConfig)
        if not config.active:
            return None
        conn = getLocal('connection')

        # Try to open connection defined in zcml
        if conn is None:
            zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
            if zcmlconfig is not None:
                logger.debug('opening connection to %s', zcmlconfig.host)
                conn = FtwSolrConnection(host=zcmlconfig.host,
                                         solrBase=zcmlconfig.base,
                                         persistent=True)
                setLocal('connection', conn)

        # Open connection defined in control panel if we don't have one yet.
        if conn is None and config.host is not None:
            host = '%s:%d' % (config.host, config.port)
            logger.debug('opening connection to %s', host)
            conn = FtwSolrConnection(host=host, solrBase=config.base,
                                     persistent=True)
            setLocal('connection', conn)
        return conn
示例#6
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
示例#7
0
文件: manager.py 项目: FHNW/ftw.solr
    def getConnection(self):
        """ returns an existing connection or opens one """
        config = getUtility(ISolrConnectionConfig)
        if not config.active:
            return None
        conn = getLocal('connection')

        # Try to open connection defined in zcml
        if conn is None:
            zcmlconfig = queryUtility(IZCMLSolrConnectionConfig)
            if zcmlconfig is not None:
                logger.debug('opening connection to %s', zcmlconfig.host)
                conn = FtwSolrConnection(host=zcmlconfig.host,
                                         solrBase=zcmlconfig.base,
                                         persistent=True)
                setLocal('connection', conn)

        # Open connection defined in control panel if we don't have one yet.
        if conn is None and config.host is not None:
            host = '%s:%d' % (config.host, config.port)
            logger.debug('opening connection to %s', host)
            conn = FtwSolrConnection(host=host,
                                     solrBase=config.base,
                                     persistent=True)
            setLocal('connection', conn)
        return conn
示例#8
0
 def closeConnection(self, clearSchema=False):
     """ close the current connection, if any """
     logger.debug('closing connection')
     conn = getLocal('connection')
     if conn is not None:
         conn.close()
         setLocal('connection', None)
     if clearSchema:
         setLocal('schema', None)
示例#9
0
 def closeConnection(self, clearSchema=False):
     """ close the current connection, if any """
     logger.debug('closing connection')
     conn = getLocal('connection')
     if conn is not None:
         conn.close()
         setLocal('connection', None)
     if clearSchema:
         setLocal('schema', None)
示例#10
0
 def _getSchema(self):
     """ returns the currently used schema or fetches it """
     manager, proc, conn= self._get_man_proc_conn()
     schema = getLocal('schema')
     if schema is None:
         if conn is not None:
             logger.debug('getting schema from solr')
             try:
                 schema = conn.getSchema()
                 setLocal('schema', schema)
             except (error, CannotSendRequest, ResponseNotReady):
                 logger.exception('exception while getting schema')
     return schema
示例#11
0
 def _getConnection(self):
     """ returns an existing connection or opens one """
     config = getUtility(ISolrConnectionConfig,context=self.context)
     if not config.active:
         return None
     conn = getLocal('connection')
     if conn is None and config.host is not None:
         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
示例#12
0
 def getSchema(self):
     """ returns the currently used schema or fetches it """
     schema = getLocal('schema')
     if schema is None:
         conn = self.getConnection()
         if conn is not None:
             logger.debug('getting schema from solr')
             try:
                 schema = conn.getSchema()
                 setLocal('schema', schema)
             except (error, CannotSendRequest, ResponseNotReady):
                 logger.exception('exception while getting schema')
     return schema
示例#13
0
 def getSchema(self):
     """ returns the currently used schema or fetches it """
     schema = getLocal("schema")
     if schema is None:
         conn = self.getConnection()
         if conn is not None:
             logger.debug("getting schema from solr")
             self.setSearchTimeout()
             try:
                 schema = conn.get_schema()
                 setLocal("schema", schema)
             except (error, CannotSendRequest, ResponseNotReady):
                 logger.exception("exception while getting schema")
     return schema
示例#14
0
 def getConnection(self):
     """ returns an existing connection or opens one """
     config = getUtility(ISolrConnectionConfig)
     if not config.active:
         return None
     conn = getLocal('connection')
     if conn is None and config.host is not None:
         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
示例#15
0
 def getSchema(self):
     """ returns the currently used schema or fetches it """
     schema = getLocal('schema')
     if schema is None:
         conn = self.getConnection()
         if conn is not None:
             logger.debug('getting schema from solr')
             self.setSearchTimeout()
             try:
                 schema = conn.get_schema()
                 setLocal('schema', schema)
             except (error, CannotSendRequest, ResponseNotReady):
                 logger.exception('exception while getting schema')
     return schema
示例#16
0
 def closeConnection(self, clearSchema=False, core=None):
     """ close the current connection, if any """
     logger.debug('closing connection')
     if core is None:
         connection_key = 'connection'
         schema_key = 'schema'
     else:
         connection_key = 'connection_{0}'.format(core)
         schema_key = 'schema_{0}'.format(core)
     conn = getLocal(connection_key)
     if conn is not None:
         conn.close()
         setLocal(connection_key, None)
     if clearSchema:
         setLocal(schema_key, None)
示例#17
0
 def closeConnection(self, clearSchema=False, core=None):
     """ close the current connection, if any """
     logger.debug('closing connection')
     if core is None:
         connection_key = 'connection'
         schema_key = 'schema'
     else:
         connection_key = 'connection_{0}'.format(core)
         schema_key = 'schema_{0}'.format(core)
     conn = getLocal(connection_key)
     if conn is not None:
         conn.close()
         setLocal(connection_key, None)
     if clearSchema:
         setLocal(schema_key, None)
示例#18
0
 def getConnection(self):
     """ returns an existing connection or opens one """
     config = getUtility(ISolrConnectionConfig)
     if not config.active:
         return None
     conn = getLocal('connection')
     host_ = SOLR_PRODUCTCONFIG_HOST or config.host
     port_ = SOLR_PRODUCTCONFIG_PORT or config.port
     base_ = SOLR_PRODUCTCONFIG_BASE or config.base
     if conn is None and host_ is not None:
         host = '%s:%d' % (host_, port_)
         logger.debug('opening connection to %s', host)
         conn = SolrConnection(host=host, solrBase=base_,
             persistent=True)
         setLocal('connection', conn)
     return conn
示例#19
0
 def getSchema(self, core=None):
     """ returns the currently used schema or fetches it """
     if core is None:
         schema_key = 'schema'
     else:
         schema_key = 'schema_{0}'.format(core)
     schema = getLocal(schema_key)
     if schema is None:
         conn = self.getConnection(core)
         if conn is not None:
             logger.debug('getting schema from solr')
             self.setSearchTimeout()
             try:
                 schema = conn.get_schema()
                 setLocal(schema_key, schema)
             except (error, CannotSendRequest, ResponseNotReady):
                 logger.exception('exception while getting schema')
     return schema
示例#20
0
 def getSchema(self, core=None):
     """ returns the currently used schema or fetches it """
     if core is None:
         schema_key = 'schema'
     else:
         schema_key = 'schema_{0}'.format(core)
     schema = getLocal(schema_key)
     if schema is None:
         conn = self.getConnection(core)
         if conn is not None:
             logger.debug('getting schema from solr')
             self.setSearchTimeout()
             try:
                 schema = conn.get_schema()
                 setLocal(schema_key, schema)
             except (error, CannotSendRequest, ResponseNotReady):
                 logger.exception('exception while getting schema')
     return schema
示例#21
0
def pingSolr():
    """ test if the solr server is available """
    status = getLocal("solrStatus")
    if status is not None:
        return status
    conn = HTTPConnection("localhost", 8983)
    try:
        conn.request("GET", "/solr/plone/admin/ping")
        response = conn.getresponse()
        status = response.status == 200
        msg = "INFO: solr return status '%s'" % response.status
    except error as e:
        status = False
        msg = 'WARNING: solr tests could not be run: "%s".' % e
    if not status:
        print(file=stderr)
        print("*" * len(msg), file=stderr)
        print(msg, file=stderr)
        print("*" * len(msg), file=stderr)
        print(file=stderr)
    setLocal("solrStatus", status)
    return status
示例#22
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
示例#23
0
def pingSolr():
    """ test if the solr server is available """
    status = getLocal('solrStatus')
    if status is not None:
        return status
    conn = HTTPConnection('localhost', 8983)
    try:
        conn.request('GET', '/solr/admin/ping')
        response = conn.getresponse()
        status = response.status == 200
        msg = "INFO: solr return status '%s'" % response.status
    except error, e:
        status = False
        msg = 'WARNING: solr tests could not be run: "%s".' % e
    if not status:
        print >> stderr
        print >> stderr, '*' * len(msg)
        print >> stderr, msg
        print >> stderr, '*' * len(msg)
        print >> stderr
    setLocal('solrStatus', status)
    return status


def numFound(result):
    match = search(r'numFound="(\d+)"', result)
    if match is not None:
        match = int(match.group(1))
    return match
示例#24
0
def pingSolr():
    """ test if the solr server is available """
    status = getLocal('solrStatus')
    if status is not None:
        return status
    conn = HTTPConnection('localhost', 8983)
    try:
        conn.request('GET', '/solr/admin/ping')
        response = conn.getresponse()
        status = response.status == 200
        msg = "INFO: solr return status '%s'" % response.status
    except error, e:
        status = False
        msg = 'WARNING: solr tests could not be run: "%s".' % e
    if not status:
        print >> stderr
        print >> stderr, '*' * len(msg)
        print >> stderr, msg
        print >> stderr, '*' * len(msg)
        print >> stderr
    setLocal('solrStatus', status)
    return status


def numFound(result):
    match = search(r'numFound="(\d+)"', result)
    if match is not None:
        match = int(match.group(1))
    return match