コード例 #1
0
def cria_solr(colecao, timeout=40):
    zookeeper = pysolr.ZooKeeper(
        "bda1node05:2181,bda1node06:2181,bda1node07:2181/solr")
    return pysolr.SolrCloud(zookeeper,
                            colecao,
                            always_commit=False,
                            timeout=timeout)
コード例 #2
0
def connect_to_solr(zookeeper_server):
    print(zookeeper_server)
    zookeeper = pysolr.ZooKeeper(zookeeper_server)
    return pysolr.SolrCloud(zookeeper,
                            "log_files",
                            timeout=300,
                            auth=kerberos_auth)
コード例 #3
0
 def _get_connection(self) -> pysolr.Solr:
     if self._zk_url:
         zk = pysolr.ZooKeeper(f"{self._zk_url}")
         collections = {}
         for c in zk.zk.get_children("collections"):
             collections.update(
                 json.loads(
                     zk.zk.get("collections/{}/state.json".format(c))
                     [0].decode("ascii")))
         zk.collections = collections
         return pysolr.SolrCloud(zk, self._collection, always_commit=True)
     elif self._solr_url:
         return pysolr.Solr(f'{self._solr_url}/solr/{self._collection}',
                            always_commit=True)
     else:
         raise RuntimeError(
             "You must provide either solr_host or zookeeper_host.")
コード例 #4
0
def get_solr_client():
    logger = DebugLogger('app.api.solr_client.get_solr_client').get_logger()

    if settings.APP_ENV != 'mcaas':
        try:
            logger.info('Connecting To Zookeeper Ensemble: %s',
                        settings.ZK_HOST)
            zookeeper = pysolr.ZooKeeper(settings.ZK_HOST)
        except:
            e = sys.exc_info()[0]
            f = sys.exc_info()[1]
            g = sys.exc_info()[2]
            logger.warn('Error Occured: %s \n %s \n %s \n', e, f, g)
            return False

        try:
            logger.info('Connecting To Solr %s Collection',
                        settings.SOLR_COLLECTION)
            return pysolr.SolrCloud(zookeeper,
                                    settings.SOLR_COLLECTION,
                                    results_cls=dict)
        except:
            e = sys.exc_info()[0]
            f = sys.exc_info()[1]
            g = sys.exc_info()[2]
            logger.warn('Error Occured: %s \n %s \n %s \n', e, f, g)
            return False
    else:
        try:
            logger.info('Connecting to Solr At %s', settings.SOLR_HOST)
            solr = pysolr.Solr(settings.SOLR_HOST, results_cls=dict)
            return solr
        except:
            e = sys.exc_info()[0]
            f = sys.exc_info()[1]
            g = sys.exc_info()[2]
            logger.warn('Error Occured: %s \n %s \n %s \n', e, f, g)
            return False
コード例 #5
0
ファイル: source.py プロジェクト: sodre/intake-solr
    def __init__(self,
                 query,
                 base_url,
                 core,
                 qargs=None,
                 metadata=None,
                 auth=None,
                 cert=None,
                 zoocollection=False):
        self.query = query
        self.qargs = qargs or {}
        self.metadata = metadata or {}
        self._schema = None
        if auth == 'kerberos':
            from requests_kerberos import HTTPKerberosAuth, OPTIONAL
            auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL,
                                    sanitize_mutual_error_response=False)
        if zoocollection:
            url = ','.join(['/'.join([b, core]) for b in base_url.split(',')])
            zoo = pysolr.ZooKeeper(url)
            if auth or cert:
                self.solr = pysolr.SolrCloud(zoo,
                                             zoocollection,
                                             auth=auth,
                                             verify=cert)
            else:
                # conda released pysolr does not support auth=
                self.solr = pysolr.SolrCloud(zoo, zoocollection)
        else:
            url = '/'.join([base_url, core])
            if auth or cert:
                self.solr = pysolr.Solr(url, auth=auth, verify=cert)
            else:
                # conda released pysolr does not support auth=
                self.solr = pysolr.Solr(url)

        super(SOLRSequenceSource, self).__init__(metadata=metadata)
コード例 #6
0
def search_by_solr(solr_condtitions):
    """ 通过Solr完成检索 """
    zookeeper = pysolr.ZooKeeper(SOLR_ZOOKEEPER)
    solr = pysolr.SolrCloud(zookeeper, SOLR_COLLECTION)
    results = solr.search(solr_condtitions)
    return map(lambda result: result["id"], results)
コード例 #7
0
def connect_to_zookeeper(zkhosts='localhost:2181'):
    '''
    zookeeper = connect_to_zookeeper(zkhosts='localhost:2181')
    '''
    #pysolr.ZooKeeper("zkhost1:2181,zkhost2:2181,zkhost3:2181")
    return pysolr.ZooKeeper(zkhosts)
コード例 #8
0
def __init_solr():
    #    pysolr.ZooKeeper.CLUSTER_STATE = '/collections/datalayer/state.json'
    zookeeper = pysolr.ZooKeeper(os.getenv('DLA_SOLR_ZK_HOST'))
    global solr
    solr = pysolr.SolrCloud(zookeeper, "datalayer", always_commit=True)
コード例 #9
0
def create_solr_client():
    return SolrClient(
        pysolr.ZooKeeper(settings.ZOOKEEPER_SERVER),
        collection=settings.PLACAS_SOLR_COLLECTION,
    )
コード例 #10
0
ファイル: main.py プロジェクト: kiemkhach/TKVTDTT
def connect():
    pysolr.ZooKeeper.CLUSTER_STATE = '/collections/viblo_posts/state.json'
    zookeeper = pysolr.ZooKeeper("localhost:9983")
    solr = pysolr.SolrCloud(zookeeper, 'viblo_posts')
    return solr
コード例 #11
0
def connect_to_solr(zookeeper_server):
    zookeeper = pysolr.ZooKeeper(zookeeper_server)
    return pysolr.SolrCloud(zookeeper,
                            "files_detran",
                            timeout=300,
                            auth=kerberos_auth)