Skip to content
This repository has been archived by the owner on Apr 6, 2019. It is now read-only.

Commit

Permalink
Ensure sort order enforcement doesn't DISTINCT-ify result set.
Browse files Browse the repository at this point in the history
  • Loading branch information
yhahn committed Jun 10, 2010
1 parent 615e9c9 commit 2ac389b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
23 changes: 18 additions & 5 deletions views/searchlight_plugin_query_v2.inc
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,25 @@ class searchlight_plugin_query extends views_query {
$view->execute();

// Ensure the order of the result set from Views matches that of the
// search backend.
$result = array_fill_keys($this->search_result['result'], NULL);
foreach ($view->result as $row) {
$result[$row->{$view->base_field}] = $row;
// search backend. Don't attempt to do this for aggregate queries.
if (empty($this->has_aggregate)) {
$sortmap = array();
$positions = array_flip(array_values($this->search_result['result']));
$i = count($positions);
foreach ($view->result as $num => $row) {
$key = $row->{$view->base_field};
// If in search results use its position in the resultset.
if (isset($positions[$key])) {
$sortmap[$num] = $positions[$key];
}
// If not, move to the end of the stack.
else {
$sortmap[$num] = $i;
$i++;
}
}
array_multisort($sortmap, $view->result);
}
$view->result = array_values(array_filter($result));
}
}
}
Expand Down
23 changes: 18 additions & 5 deletions views/searchlight_plugin_query_v3.inc
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,25 @@ class searchlight_plugin_query extends views_plugin_query_default {

if ($view->built && !empty($this->search_result)) {
// Ensure the order of the result set from Views matches that of the
// search backend.
$result = array_fill_keys($this->search_result['result'], NULL);
foreach ($view->result as $row) {
$result[$row->{$view->base_field}] = $row;
// search backend. Don't attempt to do this for aggregate queries.
if (empty($this->has_aggregate)) {
$sortmap = array();
$positions = array_flip(array_values($this->search_result['result']));
$i = count($positions);
foreach ($view->result as $num => $row) {
$key = $row->{$view->base_field};
// If in search results use its position in the resultset.
if (isset($positions[$key])) {
$sortmap[$num] = $positions[$key];
}
// If not, move to the end of the stack.
else {
$sortmap[$num] = $i;
$i++;
}
}
array_multisort($sortmap, $view->result);
}
$view->result = array_values(array_filter($result));
}
}
}
Expand Down

0 comments on commit 2ac389b

Please sign in to comment.