本文整理汇总了PHP中ArrayUtils::arraySortUsingKeys方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::arraySortUsingKeys方法的具体用法?PHP ArrayUtils::arraySortUsingKeys怎么用?PHP ArrayUtils::arraySortUsingKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils::arraySortUsingKeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search
public function search(NodeQuery $dto)
{
$searchSafe = $dto->getParameter('SearchKeywords');
$searchRaw = $dto->getParameter('SearchKeywordsRaw') == null ? preg_replace("/[\\(\\)\\/\\*\\[\\]\\?]+/", '', $searchSafe) : $dto->getParameter('SearchKeywordsRaw');
$searchThreshold = $dto->getParameter('SearchThreshold');
$maxresults = $dto->getParameter('SearchMaxResults') != null ? $dto->getParameter('SearchMaxResults') : 500;
$sortCol = $dto->getParameter('SearchSort') != null ? $dto->getParameter('SearchSort') : 'relevance';
$sortDir = $dto->getParameter('SearchSortDirection') != null ? $dto->getParameter('SearchSortDirection') : 'desc';
// $stopwords = array ('/\bof\b/','/\ba\b/','/\band\b/','/\bthe\b/');
// $s = str_replace('+','\+',$searchRaw);
// $s = preg_replace($stopwords,' ',$s);
//$s = preg_replace("/\s+/",' ',$s);
$s = preg_replace("/\\s+/", ' ', $searchRaw);
// execute query
$rows = $this->executeIndexQuery($this->getReadConnection(), $dto, $s, $searchSafe, $maxresults);
if (sizeof($rows) == 0) {
return $dto;
}
$datascore = $this->columnScores();
$words = StringUtils::wordsTokenized($s);
$scores = array();
$sorts = array();
$resultingNodeRefs = array();
$preg_s = preg_quote(str_replace(array('*', '+', '-'), '', $s), '/');
$ct = 0;
foreach ($rows as $row) {
$negative_match = FALSE;
$found = array();
if ($ct++ > $maxresults) {
break;
}
$score = $row['Score'];
if (preg_match("/^{$preg_s}/i", $row['Title'])) {
$score += 10;
} elseif (sizeof($words) == 1 && preg_match("/\\b" . $preg_s . "/i", $row['Title'])) {
$score += 5;
}
foreach ($datascore as $param => $val) {
if (!empty($s) && !empty($row[$param]) && preg_match("/\\b" . $preg_s . "\\b/si", " " . $row[$param] . " ")) {
$score += $val;
}
$m[$param] = 0;
foreach ($words as $word) {
if (preg_match("/^-(.{2,})/", $word, $m) && preg_match("/\\b{$m['1']}\\b/is", $row[$param])) {
$negative_match = TRUE;
}
$preg_word = preg_quote($word, '/');
if (!empty($word) && preg_match("/\\b{$preg_word}\\b/si", " " . $row[$param] . " ")) {
if (!isset($m[$param])) {
$m[$param] = 0;
}
$m[$param]++;
$found[$word] = 1;
$score += $val / 2;
}
}
if (isset($m[$param]) && $m[$param] == sizeof($words)) {
$score += $val * 3;
}
}
if (sizeof($found) > 0) {
$score = $score * (sizeof($found) / sizeof($words));
}
$rowElement = $this->ElementService->getByID($row['ElementID']);
$rowSlug = $row['Slug'];
$rowNodeRef = new NodeRef($rowElement, $rowSlug);
$rawscores['' . $rowNodeRef] = $score;
if (!$negative_match) {
if (empty($searchThreshold) || $score > $searchThreshold) {
$resultingNodeRefs['' . $rowNodeRef] = $rowNodeRef;
$scores['' . $rowNodeRef] = $score;
$sorts['' . $rowNodeRef] = $sortCol != 'relevance' ? $row[$sortCol] : $score;
}
}
}
reset($scores);
if (sizeof($sorts) == 0) {
return $dto;
}
if (strtolower($sortDir) == 'asc') {
asort($sorts);
} else {
arsort($sorts);
}
// $this->Logger->debug($resultingNodeRefs);
// $this->Logger->debug($sorts);
$results = ArrayUtils::arraySortUsingKeys($resultingNodeRefs, array_keys($sorts));
$dto->setParameter('NodeRefs.in', $results);
$dto->setParameter('NodeRefs.fullyQualified', true);
$dto->setOrderBy('NodeRefs');
$results = $this->NodeService->findAll($dto)->getResults();
foreach ($results as $key => &$node) {
$nodeRef = $node['NodeRef'];
$node['SearchScore'] = $scores['' . $nodeRef];
// error_log($node['Title'].' ('.$node['SearchScore'].')');
}
// $keys = array_map('strval', $sorts);
$dto->setResults($results);
return $dto;
}
示例2: findAll
//.........这里部分代码省略.........
$batchLimit = $moreThan1Table ? $this->nodeDatabaseBatchLimit : $limit;
while ($batchOffset > -1) {
$rows = null;
$reorderOnce = false;
$q->LIMIT($moreThan1Table && $batchLimit > 1 ? $batchLimit + 1 : $batchLimit);
$q->OFFSET($batchOffset);
$s = (string) $q;
//$s = str_replace($firstTable, $table, $s);
//$s = str_replace($firstTableID, $tableid, $s);
$rows = $db->readAll($s);
if (empty($rows)) {
$batchOffset = -1;
break;
}
// $this->Benchmark->start('pushrows');
foreach ($rows as $k => $row) {
if ($batchLimit > 1 && $k > $batchLimit - 1) {
break;
}
$row['ElementID'] = $elementid;
// if there is no limit, push all rows
// if there is only 1 table to aggregate, push all rows
// if the index of the current result set is less than the total needed rows, push
if (is_null($limit) || !$moreThan1Table || $c < $limit + $offset) {
$row['NodeRef'] = new NodeRef($elements[$row['ElementID']], $row['Slug']);
$resultingRows[] = $row;
++$c;
} else {
if ($k >= $limit + $offset) {
// done with this table (element)
$batchOffset = -1;
break 2;
}
if (!$reorderOnce) {
$reorderOnce = true;
$resultingRows = $this->NodesHelper->sortNodes($resultingRows, $orderObjects);
}
$lastRow = $resultingRows[$c - 1];
// if this row is before the last row in the order, add it in
if (!$this->NodesHelper->compareNodes($lastRow, $row, $orderObjects)) {
$row['NodeRef'] = new NodeRef($elements[$row['ElementID']], $row['Slug']);
$resultingRows[] = $row;
//++$c;
$lastRow = null;
// else break, we're done with this table (element)
} else {
// error_log('stopped at last: '.$lastRow['Slug'].' '.$lastRow['ActiveDate']);
// error_log('stopped at: '.$row['Slug'].' '.$row['ActiveDate']);
$batchOffset = -1;
$lastRow = null;
break 2;
}
}
}
// $this->Benchmark->end('pushrows');
if (!$moreThan1Table && $offset == 0 || count($rows) < $batchLimit + 1) {
$batchOffset = -1;
} else {
$batchOffset = $batchOffset + $batchLimit;
}
}
$rows = null;
if ($qcount > 1 && $offset > 0 && $moreThan1Table && !empty($resultingRows)) {
// error_log('resorting');
// error_log('needed total: '.($limit+$offset));
$resultingRows = $this->NodesHelper->sortNodes($resultingRows, $orderObjects);
$resultingRows = $this->NodesHelper->sliceNodes($resultingRows, $limit + $offset, 0);
// $resultingRows = array_slice($resultingRows, 0, ($limit+$offset));
$c = count($resultingRows);
}
++$qcount;
$qArgs = null;
}
$queries = null;
if (!empty($resultingRows)) {
if ($offset == 0 && $moreThan1Table) {
$resultingRows = $this->NodesHelper->sortNodes($resultingRows, $orderObjects);
}
$resultingRows = $this->NodesHelper->sliceNodes($resultingRows, $limit, $offset, $moreThan1Table && $offset > 0);
}
}
if (!empty($resultingRows)) {
$resultingNodeRefs = ArrayUtils::arrayMultiColumn($resultingRows, 'NodeRef');
if ($nodeQuery->hasParameter('NodeRefs.only') && StringUtils::strToBool($nodeQuery->getParameter('NodeRefs.only')) == true) {
$nodeQuery->setResults($resultingNodeRefs);
} else {
$results = $this->NodeMultiGetDAO->multiGet($resultingNodeRefs, $nodePartials, $forceReadWrite, $checkPermissions, true);
$keys = array_map('strval', $resultingNodeRefs);
$results = ArrayUtils::arraySortUsingKeys($results, $keys);
$keys = null;
$resultingNodeRefs = null;
$nodeQuery->setResults($results);
}
}
if ($doCounts) {
$nodeQuery->setTotalRecords($totalCount);
}
$this->Benchmark->end('findall');
return $nodeQuery;
}