When I change my sort criteria to random, I begin getting repeat displays of the same node in my view. An alphabetical criteria and the random filter turns up 4 version of the same node. When the random sort criteria is removed, it goes back to displaying each node only once. I've attached an export of the view in question. Note that I have "Node:distinct" implemented as one of the filter criteria.

CommentFileSizeAuthor
#3 dealerview_fixed.txt4.7 KBmennonot
dealerview.txt4.66 KBmennonot

Comments

mennonot’s picture

Priority: Minor » Normal

I've done some experimentation and this problem seems to be tied to the "View Type: " for the page view.

When I switched the view type from Table to Full Node instead of Table View, only one instance of each node appears. But the multiple versions problem described above also appears with the List view

merlinofchaos’s picture

If this is the case, then it probably has more to do with the fields in the view than anything else; fields are not computed in the query with a node/teaser view, but they are with a list view.

Since most of your fields are CCK/location, I don't know enough about them to say, but you could probably start eliminating fields and seeing what happens.

I am 100% sure that a random sort by itself can't cause duplicates.

Also, have you tried the distinct filter?

mennonot’s picture

StatusFileSize
new4.7 KB

So I started out eliminating fields, which didn't make any difference. Then on a whim I tried switching off the "sortable" variable for the fields and suddenly the duplicates disappeared. I narrowed it down to the "Text: Available settings" field: turning off the sortable option for this column fixes the problem.

The only thing unusual about this field is that it is a select list that shows html. Here is the allowed values list:

<img alt="diamond ring" src="/files/vendor/rng.gif">
<img alt="earring" src="/files/vendor/erng.gif">
<img alt="pendants" src="/files/vendor/pend.gif">
<img alt="wedding bands" src="/files/vendor/wbnd.gif">
<img alt="custom" src="/files/vendor/cstm.gif">

I guess it might make sense that in constructing a sortable column, these values may have given the views module trouble.

I've attached the new, working, export of the view in case it's of any use.

mediamash’s picture

is there a solution for double nodes when using the random filter?

onelittleant’s picture

The default implementation of the random view sort is problematic for many reasons... it should only be used for views that display a single page or block of results that are different every time the page is refreshed.

If what you want is something more persistent, like getting random results, but in the same order, that don't change from page to page, here's a solution that will give each site visitor, on a per-session basis, a different, repeatable random order of results.

First, implement hook_views_tables and define a sort as follows (you have to define more than just ['sorts'] on a table definition, including 'name' and 'join', but the details don't matter so long as you're not defining fields or filters, but just a single sort with its own handler, see details here: http://drupal.org/handbook/modules/views/api):

...

$mytable['sorts']['sessrand'] = array(
  'name' => t('Repeatable Random Order'),
  'help' => 'Randomly sorts nodes on a per-session basis.  Each user session gets a distinct, repeatable random set of results.',
  'handler' => 'mymodule_views_handler_sort_sessrand' 
);

Next, define the sort handler function:

function mymodule_views_handler_sort_sessrand($op, &$query, $sortinfo, $sortdata)
{
        // Do not interfere with sorting if a table header has been clicked for sorting.
	if(isset($_REQUEST['order'])) return;
        
        // Convert the first two hex characters of the session id to an integer and use that as the random seed.
	$query->add_orderby(null, 'RAND('.hexdec(substr(session_id(), 0, 2)).')', $sortdata['sortorder'], 'sessrand');
}

Each distinct session will get a distinct random ordering, but always the same random ordering throughout their session. If you want the repeatable randomness to be tied to something other than the session, then use some other number to set the random seed, like the user id for example for randomness tied to each individual user rather than session.

Note: This works in MySQL. I don't know how to set the random seed in PGSql.

merlinofchaos’s picture

Status: Active » Closed (won't fix)

This will not be fixed in Views 1.