设置并缓存连接驱动
@param array $indexWeight ['index'=>'calculate_weight']
549450
private function chooseDriver($indexWeight)
    {
        $sum = end($indexWeight);
        reset($indexWeight);
        $threshold = mt_rand(1, $sum); //权重小于1的服务器不会被选中
        foreach ($indexWeight as $index => $weight) {
            if ($weight >= $threshold) {
                break;
            }
        }

        //尝试缓存链接
        if (!isset(self::$servers[$this->serverName][$index])) {
            if (!isset(self::$servers[$this->serverName])) {
                self::$servers[$this->serverName] = [];
            }
            $config                                   = Linker::Config()::get('servers')[$this->serverName][$index];
            self::$servers[$this->serverName][$index] = $this->newConnection($config, $index); //调用子类方法获得链接实例
        }

        return $index;
    }
111588
public function remove($indexValue)
    {
        if (\is_object($indexValue)) {
            foreach ($this->arrCollection as $collectionIndex => $model) {
                if ($indexValue === $model) {
                    unset($this->arrCollection[$collectionIndex]);
                }
            }
        } else {
            unset($this->arrCollection[$indexValue]);
        }

        $this->arrCollection = \array_values($this->arrCollection);
    }
970373
public function addWeightFunction(float $weight, AbstractQuery $filter = null): self
    {
        return $this->addFunction('weight', $weight, $filter);
    }
75607
protected void taggingWeightWithWordFrequency(List<Word> words1, List<Word> words2){
        if(words1.get(0).getWeight() != null || words2.get(0).getWeight() != null){
            if(LOGGER.isDebugEnabled()){
                LOGGER.debug("词已经被指定权重，不再使用词频进行标注");
            }
            return;
        }
        //词频统计
        Map<String, AtomicInteger> frequency1 = frequency(words1);
        Map<String, AtomicInteger> frequency2 = frequency(words2);
        //输出词频统计信息
        if(LOGGER.isDebugEnabled()){
            LOGGER.debug("词频统计1：\n{}", formatWordsFrequency(frequency1));
            LOGGER.debug("词频统计2：\n{}", formatWordsFrequency(frequency2));
        }
        //权重标注
        words1.parallelStream().forEach(word->{
            word.setWeight(frequency1.get(word.getText()).floatValue());
        });
        words2.parallelStream().forEach(word->{
            word.setWeight(frequency2.get(word.getText()).floatValue());
        });
    }
276388
public function setWeight(int $weight): void
    {
        if ($weight < 0 || $weight > static::MAX_WEIGHT) {
            throw new \InvalidArgumentException('Weight must be an unsigned integer on the range [0-65535]');
        }

        $this->weight = $weight;
    }
551701
public function set($index, $value = null)
    {
        if (is_array($index)) {
            $this->data = array_merge($this->data, $index);
        } else {
            $this->data[$index] = $value;
        }
        return $this;
    }
62506
public int getWeight() {
        ProviderStatus status = getStatus();
        if (status == ProviderStatus.WARMING_UP) {
            try {
                // 还处于预热时间中
                Integer warmUpWeight = (Integer) getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT);
                if (warmUpWeight != null) {
                    return warmUpWeight;
                }
            } catch (Exception e) {
                return weight;
            }
        }
        return weight;
    }
831511
public function createIndex(Index $index, $table)
    {
        $this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
    }
450320
private function _rindex($index, array $values) : int
    {
        if (is_int($index) && $index < 0){
            return count($values) + $index;
        }
        return $index;
    }
108200
public function setQueryWeight(float $weight): Query
    {
        $query = $this->getParam('query');
        $query['query_weight'] = $weight;

        return $this->setParam('query', $query);
    }
1247279
public function setConfigurableAttributeWeights($attribute_set = 'default', array $weights = []) {
    $attribute_set = strtolower($attribute_set);

    // Update weights for particular attribute set in config.
    $existing_weights = $this->config->get('attribute_weights');
    $existing_weights[$attribute_set] = $weights;

    $config = $this->configFactory->getEditable(self::CONFIG_KEY);
    $config->set('attribute_weights', $existing_weights);
    $config->save();

    // Reload config.
    $this->config = $this->configFactory->get(self::CONFIG_KEY);
  }
73140
protected function output(array $sample)
    {
        $sum = 0;
        foreach ($this->weights as $index => $w) {
            if ($index == 0) {
                $sum += $w;
            } else {
                $sum += $w * $sample[$index - 1];
            }
        }

        return $sum;
    }
769223
public function setRescoreQueryWeight(float $weight): Query
    {
        $query = $this->getParam('query');
        $query['rescore_query_weight'] = $weight;

        return $this->setParam('query', $query);
    }
850182
public function setIndex($index)
    {
        if ($this->index !== $index) {
            $this->index = $index;
            $this->addOrUpdate();
        }
    }
1276185
public static function weightedMean(array $values, array $weights, ?int $n = null) : float
    {
        $n = $n ?? count($values);

        if ($n < 1) {
            throw new InvalidArgumentException('Mean is undefined for empty'
                . ' set.');
        }

        if (count($weights) !== $n) {
            throw new InvalidArgumentException('The number of weights must'
                . ' equal the number of values.');
        }

        $total = array_sum($weights) ?: EPSILON;

        $temp = 0.;

        foreach ($values as $i => $value) {
            $temp += $value * ($weights[$i] ?: EPSILON);
        }

        return $temp / $total;
    }
673221
static function getServer(array $servers)
    {
        $weight = 0;
        //移除不在线的节点
        foreach ($servers as $k => $svr)
        {
            //节点已掉线
            if (!empty($svr['status']) and $svr['status'] == 'offline')
            {
                unset($servers[$k]);
            }
            else
            {
                $weight += $svr['weight'];
            }
        }
        //计算权重并随机选择一台机器
        $use = rand(0, $weight - 1);
        $weight = 0;
        foreach ($servers as $k => $svr)
        {
            //默认100权重
            if (empty($svr['weight']))
            {
                $svr['weight'] = 100;
            }
            $weight += $svr['weight'];
            //在权重范围内
            if ($use < $weight)
            {
                return $svr;
            }
        }
        //绝不会到这里
        $servers = array_values($servers);
        return $servers[0];
    }
52328
public function setWeight($weight)
    {
        if ($weight < 0.1) {
            throw new InvalidArgumentException("Expected weight greater than 100g.");
        }

        $this->set(Config::T530, (string)round($weight, 2));

        return $this;
    }