Note that there are some explanatory texts on larger screens.

plurals
  1. POThinking Sphinx without condition
    primarykey
    data
    text
    <p>I have a following model:</p> <pre><code>class Article &lt; ActiveRecord::Base define_index do indexes content indexes :name, sortable: true has type end end </code></pre> <p>and special type of an article is:</p> <pre><code>class About &lt; Article end </code></pre> <p>and the same for <code>Contact</code></p> <p>I would like to have searchable articles index action without articles with type of "About" or "Contact"</p> <pre><code>class ArticlesController &lt; ApplicationController load_and_authorize_resource def index @articles = Article.search(params[:search], :with_all =&gt; {:type =&gt; nil}, :page =&gt; params[:page], :per_page =&gt; 10) end end </code></pre> <p>But the <code>@articles</code> instance variable contains everytime also "About" &amp; "Contact" articles.</p> <p>This is very strange (seems like will_paginate messing everything up):</p> <pre><code>@articles = Article.search( :without =&gt; {:type =&gt; %w(About Contact)}).include?(About.first) # false @articles = Article.search( :without =&gt; {:type =&gt; %w(About Contact)}, :page =&gt; 1, :per_page =&gt; 1000).include?(About.first) # true </code></pre> <p>=============================================================================</p> <p>Finally I did:</p> <pre><code>class Article &lt; ActiveRecord::Base define_index do indexes content indexes :name, sortable: true has "CRC32(type)", :as =&gt; :article_type, :type =&gt; :integer end end </code></pre> <p>and:</p> <pre><code>class ArticlesController &lt; ApplicationController load_and_authorize_resource def index @articles = Article.search(params[:search], :without =&gt; {:article_type =&gt; ["About".to_crc32, "Contact".to_crc32]}, :page =&gt; params[:page], :per_page =&gt; 10) end end </code></pre> <p>and it works. Thanks guys!</p>
    singulars
    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. 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