title: Sort by filter field and text match ranking in sphinx
body: <p>Right now I'm using Sphinx to make text search over some entities in my database. For simplicity lets asume that these entities are Clients with a name, description and a role field. </p>
  
  <p>I do text search over name with weight 200 and over the description with weight 50 on matches on those fields. Everything works as expected. The problem is that right now I need to order by role, leaving role 1 always first. </p>
  
  <p>On a normal query I would do something like</p>
  
  <p>... ORDER BY c.role DESC, c.sphinx_ranking DESC</p>
  
  <p>Is this possible using only sphinx? I know that is posible to sort by a filter but i don't know if is possible to use both, the text weight order AND the field role.</p>
  
  <p><strong>Solved:</strong>
  I found the answer reading Sphinx documentation. If someone has the same problem here is the solution:</p>
  
  <p>To mix both, the weight from sphinx and a field that works as a filter you must use SPH_SORT_EXTENDED as Sort Mode and as parameter you pass the fields like in a SQL statement.</p>
  
  <p>On my case, I'm using php so the code is this:</p>
  
  <pre><code>$sphinxclient-&gt;SetSortMode(SPH_SORT_EXTENDED,"role DESC,@weight DESC"); 
  </code></pre>
  
  <p>Where @weight is the Sphinx Ranking value and role is a field on my table. With this I get the clients whose role is 1 first and then the result is sorted by sphinx text rating. Very Simple! </p>