Find common surnames.

@param int    $threshold
@param int    $number_of_surnames
@param string $sorting

@return string
8862
public function commonSurnamesTotals(
        int $threshold = 1,
        int $number_of_surnames = 10,
        string $sorting = 'rcount'
    ): string {
        return $this->commonSurnamesQuery('nolist', true, $threshold, $number_of_surnames, $sorting);
    }
836099
public function findBy(array $criteria, ?array $sorting = null, $limit = null, $offset = null)
    {
        $queryBuilder = $this->getCollectionQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);
        $this->applySorting($queryBuilder, $sorting);

        if (null !== $limit) {
            $queryBuilder->limit($limit);
        }

        if (null !== $offset) {
            $queryBuilder->skip($offset);
        }

        return $queryBuilder
            ->getQuery()
            ->getIterator()
        ;
    }
480676
public function getCommonSurname(): string
    {
        $top_surname = $this->topSurnames(1, 0);
        
        return $top_surname
            ? implode(', ', array_keys(array_shift($top_surname)) ?? [])
            : '';
    }
479716
private function processOrderByParams($sort)
    {
        $direction       = (substr($sort, 0, 1) == '-') ? 'DESC' : 'ASC';
        $field           = (substr($sort, 0, 1) == '-') ? substr($sort, 1) : $sort;
        $this->orderBy[] = [
            snake_case($field),
            $direction
        ];
    }
979043
private function sortXML (array $sort) {
		// On no count, no need to sort
		if (count($sort) == 0) {
			return '';
		}

		$queryString = '';
		foreach ($sort as $col => $value) {
			$queryString .= '<FieldRef Name="' . $col . '" Ascending="' . $this->getSortFromValue($value) . '" />';
		}
		return '<OrderBy>' . $queryString . '</OrderBy>';
	}
649952
protected function _toSequenceString($sort = true)
    {
        if (empty($this->_ids)) {
            return '';
        }

        $in = $this->_ids;

        if ($sort && !$this->_sorted) {
            $this->_sort($in);
        }

        $first = $last = array_shift($in);
        $i = count($in) - 1;
        $out = array();

        foreach ($in as $key => $val) {
            if (($last + 1) == $val) {
                $last = $val;
            }

            if (($i == $key) || ($last != $val)) {
                if ($last == $first) {
                    $out[] = $first;
                    if ($i == $key) {
                        $out[] = $val;
                    }
                } else {
                    $out[] = $first . ':' . $last;
                    if (($i == $key) && ($last != $val)) {
                        $out[] = $val;
                    }
                }
                $first = $last = $val;
            }
        }

        return empty($out)
            ? $first
            : implode(',', $out);
    }
164370
public function findBy(array $criteria, ?array $sort = null, $limit = null, $skip = null) : array
    {
        return $this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip)->toArray();
    }
1043501
public function build(array $tokenProbabilities, $threshold = 50)
    {
        $sentences = [''];

        foreach ($tokenProbabilities as $idx => $tokenProbability) {
            $token = $tokenProbability->getToken();

            $sentenceIdx = count($sentences) - 1;
            $sentences[$sentenceIdx] .= $token->getPrintableValue();

            $meetsThreshold = $tokenProbability->getProbability() >= $threshold;
            $currentSentenceIsEmpty = empty(trim($sentences[$sentenceIdx]));

            if ($meetsThreshold && !$currentSentenceIsEmpty) {
                $sentences[] = '';
            }
        }

        if ('' === $sentences[count($sentences) - 1]) {
            unset($sentences[count($sentences) - 1]);
        }

        $sentences = array_map('ltrim', $sentences);

        return $sentences;
    }
231028
public function sort(Sorting $sorting)
	{
		if (is_callable($sorting->getSortCallback())) {
			call_user_func(
				$sorting->getSortCallback(),
				$this->criteria,
				$sorting->getSort()
			);

			return $this;
		}

		if ($sort = $sorting->getSort()) {
			$this->criteria->orderBy($sort);
			return $this;
		}

		$this->criteria->orderBy([$this->primary_key => 'ASC']);

		return $this;
	}
549255
public function commonGivenUnknownTable(int $threshold = 1, int $maxtoshow = 10): string
    {
        return $this->commonGivenQuery('U', 'table', false, $threshold, $maxtoshow);
    }
221582
public function sortRecords(array $sorting)
    {
        if (!$this->writeConnection) {
            throw new AnyContentClientException ('Current connection(s) doesn\'t support write operations.');
        }

        $records = $records = $this->getRecords();
        foreach ($records as $record) {
            $record->setPosition(null);
            $record->setParent(null);
        }

        $positions = [];
        foreach ($sorting as $recordId => $parentId) {
            if (!array_key_exists($parentId, $positions)) {
                $positions[$parentId] = 1;
            }

            $records[$recordId]->setPosition($positions[$parentId]++);
            $records[$recordId]->setParent($parentId);
        }

        return $this->saveRecords($records);
    }
816682
public function commonGivenUnknownList(int $threshold = 1, int $maxtoshow = 10): string
    {
        return $this->commonGivenQuery('U', 'list', false, $threshold, $maxtoshow);
    }
304731
private static function handleSort($query, $sort = null)
    {
        $replace = '';

        if ($sort !== null) {
            $sort ->validate(static::class);

            $tableAttribute = (
                $sort->table === null
                ? $sort->attribute
                : $sort->table . '"."' .$sort->attribute
            );

            $replace = "\n" . sprintf(
                'ORDER BY "%s" %s',
                $tableAttribute,
                ($sort->ascending ? 'ASC' : 'DESC')
            );
        }

        $query = str_replace(
            '{{sort}}',
            $replace,
            $query
        );

        return $query;
    }
1330633
private function parseThresholds($thresholds)
	{
		$log = $this->log;

		if (strpos($thresholds, ','))
		{
			$thresholds = explode(',', $thresholds);
		}
		else
		{
			$thresholds = (array)$thresholds;
		}

		$threshold = array();
		foreach ($thresholds as $t)
		{
			preg_match('/([[:alpha:]]+)[\s]*([=|>|<])[\s]*([[:alnum:]\.]+)/', $t, $params);

			if (isset($params[1])
			 && isset($params[2])
			 && isset($params[3])
			 && $log::isField(trim($params[1])))
			{
				$threshold[trim($params[1])] = [
					'key'      => $params[1],
					'operator' => $params[2],
					'value'    => $params[3]
				];
			}
		}

		return $threshold;
	}
388056
public function commonGivenFemaleList(int $threshold = 1, int $maxtoshow = 10): string
    {
        return $this->commonGivenQuery('F', 'list', false, $threshold, $maxtoshow);
    }
396850
private function isRelativeTo($threshold, $above = true)
	{
		$threshold = ip2long($threshold);

		if (!$threshold)
		{
			throw new \RuntimeException('Invalid input, not an IP address');
		}

		return $above ? ($this->ipLong >= $threshold) : ($this->ipLong <= $threshold);
	}
645592
protected function _findRecursive($pattern, $sort = false)
    {
        list($dirs, $files) = $this->read($sort);
        $found = array();

        foreach ($files as $file) {
            if (preg_match('/^' . $pattern . '$/i', $file)) {
                $found[] = Folder::addPathElement($this->path, $file);
            }
        }
        $start = $this->path;

        foreach ($dirs as $dir) {
            $this->cd(Folder::addPathElement($start, $dir));
            $found = array_merge($found, $this->findRecursive($pattern, $sort));
        }

        return $found;
    }