This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
for ($i=1; $i <= 10; $i++) { | |
$start = microtime(true); | |
for ($ii=0; $ii < 5000; $ii++) { | |
$tids1 = $tids2 = $tids3 = array(); | |
for ($iii=0; $iii < 3; $iii++) { | |
$tids1[] = rand(500, 1000000); | |
$tids2[] = rand(500, 1000000); | |
$tids3[] = rand(500, 1000000); | |
} | |
//Stuff the randomly selected tids into an array compatible with db_query | |
$args = array( | |
":tids1" => $tids1, | |
":tids2" => $tids2, | |
":tids3" => $tids3, | |
); | |
//Get a ranked list of the 5 nodes which have the most matches | |
$query = db_query( | |
"SELECT node.nid nid | |
FROM node | |
LEFT JOIN field_data_field_tags | |
ON node.nid=field_data_field_tags.entity_id | |
WHERE field_data_field_tags.field_tags_tid | |
IN (:tids1) | |
UNION ALL SELECT node.nid nid | |
FROM node | |
LEFT JOIN field_data_field_test | |
ON node.nid=field_data_field_test.entity_id | |
WHERE field_data_field_test.field_test_tid | |
IN (:tids2) | |
UNION ALL SELECT node.nid nid | |
FROM node | |
LEFT JOIN field_data_field_test2 | |
ON node.nid=field_data_field_test2.entity_id | |
WHERE field_data_field_test2.field_test2_tid | |
IN (:tids3)", | |
$args | |
); | |
$results = $query->fetchAll(); | |
$result_array = array(); | |
foreach ($results as $result) { | |
$result_array[] = $result->nid; | |
} | |
arsort(array_count_values($result_array)); | |
$result_array = array_slice($result_array, 0, 5, true); | |
} | |
print "Run $i: " . round(microtime(true) - $start, 3) . ' seconds' . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment