Text search not working with sunspot rails -


i'm implementing basic search bar sunspot. code seems work search result returns no object. don't understand why , after reading sunspot documentation, i'm bit lost. if can give me clue, helpful. here code :

my controller:

class bookscontroller < applicationcontroller   before_action :set_book, only: [:show, :edit, :update, :destroy]   respond_to :html    def index     @search = book.search       fulltext(params[:search])     end     @books = @search.results      respond_with(@books)   end # additional code end 

my model:

class book < activerecord::base   has_many :wishs   has_many :loans    validates_presence_of :title, :author, :description    enum status: [ :available, :unavailable, :on_loan ]    searchable     string :title     string :author     string :description   end end 

my view:

<div class="container">   <div class="row">     <h1>listing books</h1>      <%= form_tag books_path, :method => :get %>         <div class="input-group">             <span class="input-group-btn">               <%= submit_tag "search", :name => nil, class: "btn btn-default" %>             </span>           <%= text_field_tag :search, params[:search], class: "form-control", placeholder: "title, description, author ..." %>         </div>     <% end %>      <table class="table table-hover" style="margin-top: 20px">       <thead>       <tr>         <!-- name of column -->       </tr>       </thead>        <tbody>       <% @books.each |book| %>         <!-- stuff -->       <% end %>       </tbody>     </table>   </div> </div> 

instead of string use text full-text search. in model try:

searchable   text :title   text :author   text :description end 

if syntax fails, work

searchable   text :title, :author, :description end 

in end, reindex looks have fixed it: bundle exec rake sunspot:solr:reindex


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -