Skip to content

Instantly share code, notes, and snippets.

@adridev
Created September 2, 2014 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adridev/463f70e292c6caf5af25 to your computer and use it in GitHub Desktop.
Save adridev/463f70e292c6caf5af25 to your computer and use it in GitHub Desktop.
Algo improved
$questions = array_values($questions);
foreach ($questions as $k => $q) {
$key = (string) 'q' . (++$k);
$questionMapping[$key] = $q;
}
$template = "
MATCH
(u:User)-[:RATES]->(q:Question)
WHERE
q.qnoow_id IN [ ";
foreach ($questionMapping as $k => $q) {
$template .= "{" . $k . "}, ";
}
$template = rtrim(trim($template), ",");
$template .= " ]
AND NOT u.qnoow_id = " . $id . "
RETURN
u.qnoow_id AS u;";
//Create the Neo4j template object
$neoQuery = new Query(
$this->client,
$template,
$questionMapping
);
try {
$result = $neoQuery->getResultSet();
} catch (\Exception $e) {
throw $e;
}
//TODO: check that the execution and integration of this function actually works :/
//TODO: enqueue the calculation of these matching instead of calculating them in a loop (launch workers?) I didn't do it myself because I don't really know how the queues work :(
foreach ($result as $row) {
$this->getMatchingBetweenTwoUsersBasedOnAnswers($id, $row['u']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment