Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it's more that <code>accessible_by</code> is probably a scope - which is Database/SQL-driven. Sphinx has its own query interface, and so ActiveRecord scopes don't apply.</p> <p>An inefficient workaround (gets all companies first):</p> <pre><code>company_ids = Company.accessible_by(current_ability).collect &amp;:id @companies = Company.search params[:search], :include =&gt; :order, :match_mode =&gt; :extended, :page =&gt; params[:page], :with =&gt; {:sphinx_internal_id =&gt; company_ids} </code></pre> <p>A couple of things to note: sphinx_internal_id is the indexed model's primary key - Sphinx has its own unique identifier named id, hence the distinction. Also: You don't want to call <code>paginate</code> on a search collection - Sphinx always paginates, so just pass the <code>:page</code> param through to the search call.</p> <p>There'd be two better workarounds that I can think of - either have a Sphinx equivalent of <code>accessible_by</code>, with the relevant information added to your indices as attributes - or, simpler if not quite as ideal, just get the company ids returned in the first line of my above snippet <em>without</em> loading up every company as an ActiveRecord object. Both will probably mean bypassing and/or duplicating Cancan's helpers.</p> <p>Although... maybe this would do the trick, taking the latter approach:</p> <pre><code>sql = Company.accessible_by(current_ability).select(:id).to_sql company_ids = Company.connection.select_values sql @companies = Company.search params[:search], :include =&gt; :order, :match_mode =&gt; :extended, :page =&gt; params[:page], :with =&gt; {:sphinx_internal_id =&gt; company_ids} </code></pre> <p>Avoids loading unnecessary Company objects, uses the Cancan helper (provided it is/returns a scope), and works neatly with what Sphinx/Thinking Sphinx expects. I've not used Cancan though, so this is a bit of guesswork.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload