Answers.Body: <p>Take a look at <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/Form/Search/Custom/RandomSegment.php" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/Form/Search/Custom/RandomSegment.php</a></p>
  
  <p>It's a little tricky because if there's multiple pages of results you don't want the second page to repeat anything on the first, so it creates the full random-ordered list first and draws from that.</p>
  
  <p>If you don't really care, or know there's only one page, you could override addSortOffset() in CRM/Contact/Form/Search/Custom/Proximity.php to do something similar to what the Base does in CRM/Contact/Form/Search/Custom/Base.php, and instead of "ORDER BY $sort", make it say "ORDER BY RAND()", e.g.</p>
  
  <pre><code>public function addSortOffset(&amp;$sql, $offset, $rowcount, $sort) {
      $sql .= " ORDER BY RAND() ";
  
      if ($rowcount &gt; 0 &amp;&amp; $offset &gt;= 0) {
        $offset = CRM_Utils_Type::escape($offset, 'Int');
        $rowcount = CRM_Utils_Type::escape($rowcount, 'Int');
  
        $sql .= " LIMIT $offset, $rowcount ";
      }
    }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-19T13:27:36.827Z
Answers.Text: Thanks for this help. How do I get the Proximity Search profile to use the RandomSegment.php?
Answers.UserDisplayName: A. Block
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-19T20:55:35.757Z
Answers.Text: No the randomsegment is an example of how to fully do random listings if you want the full treatment. But either way you'd need to edit proximity.php, or better, create a new custom search that's a copy of proximity.php and edit that. See https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-search
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-18T17:21:23.627Z
Answers.LastActivityDate: 2017-10-18T17:21:23.627Z
Answers.UserDisplayName: Demerit
Body: <p>We are using civiCRM 4.7.25 with Joomla 3.8.1</p>
  
  <p>We have a proximity search to allow people to find nearby members of an national association. </p>
  
  <p>The proximity search returns matching members alphabetically.... </p>
  
  <p>But we want the members to have "equal" opportunity to appear towards the top of the results list -- so we'd like to have the results of the proximity search return results randomly, instead of alphabetically. </p>
  
  <p>Is there a way to do this? </p>
  
Tags: <profile><joomla><search>
Title: Randomize display of results from a Proxmity Search
ThreadText: # Randomize display of results from a Proxmity Search
  
  (Asked by: username_0 on 2017-10-12)
  
  We are using civiCRM 4.7.25 with Joomla 3.8.1
  
  We have a proximity search to allow people to find nearby members of an national association.
  
  The proximity search returns matching members alphabetically....
  
  But we want the members to have "equal" opportunity to appear towards the top of the results list -- so we'd like to have the results of the proximity search return results randomly, instead of alphabetically.
  
  Is there a way to do this?
  
  **Tags:** profile, joomla, search
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-18. Score: 1
  
  Take a look at https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/Form/Search/Custom/RandomSegment.php
  It's a little tricky because if there's multiple pages of results you don't want the second page to repeat anything on the first, so it creates the full random-ordered list first and draws from that.
  If you don't really care, or know there's only one page, you could override addSortOffset() in CRM/Contact/Form/Search/Custom/Proximity.php to do something similar to what the Base does in CRM/Contact/Form/Search/Custom/Base.php, and instead of "ORDER BY $sort", make it say "ORDER BY RAND()", e.g.
  public function addSortOffset(&$sql, $offset, $rowcount, $sort) {
      $sql .= " ORDER BY RAND() ";
  
      if ($rowcount > 0 && $offset >= 0) {
        $offset = CRM_Utils_Type::escape($offset, 'Int');
        $rowcount = CRM_Utils_Type::escape($rowcount, 'Int');
  
        $sql .= " LIMIT $offset, $rowcount ";
      }
    }
  
  > **Comments:**
  > **username_0**: Thanks for this help. How do I get the Proximity Search profile to use the RandomSegment.php?  
  > **username_1**: No the randomsegment is an example of how to fully do random listings if you want the full treatment. But either way you'd need to edit proximity.php, or better, create a new custom search that's a copy of proximity.php and edit that. See https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-search  
  
  ---
  
  