Ruby on rails 文本搜索不适用于sunspot rails
我目前正在用sunspot实现一个基本的搜索栏。我的代码似乎有效,但搜索结果始终不返回任何对象。我不明白为什么,在阅读了所有的太阳黑子文档之后,我有点迷路了。如果有人能给我一个线索,那会很有帮助的。 这是我的密码: 我的控制器:Ruby on rails 文本搜索不适用于sunspot rails,ruby-on-rails,search,sunspot,Ruby On Rails,Search,Sunspot,我目前正在用sunspot实现一个基本的搜索栏。我的代码似乎有效,但搜索结果始终不返回任何对象。我不明白为什么,在阅读了所有的太阳黑子文档之后,我有点迷路了。如果有人能给我一个线索,那会很有帮助的。 这是我的密码: 我的控制器: class BooksController < ApplicationController before_action :set_book, only: [:show, :edit, :update, :destroy] respond_to :html
class BooksController < ApplicationController
before_action :set_book, only: [:show, :edit, :update, :destroy]
respond_to :html
def index
@search = Book.search do
fulltext(params[:search])
end
@books = @search.results
respond_with(@books)
end
# ADDITIONAL CODE
end
class BooksController
我的模型:
class Book < ActiveRecord::Base
has_many :wishs
has_many :loans
validates_presence_of :title, :author, :description
enum status: [ :available, :unavailable, :on_loan ]
searchable do
string :title
string :author
string :description
end
end
classbook
我的看法是:
<div class="container">
<div class="row">
<h1>Listing books</h1>
<%= form_tag books_path, :method => :get do %>
<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 do |book| %>
<!-- DO SOME STUFF -->
<% end %>
</tbody>
</table>
</div>
</div>
图书目录
:get-do%>
无,类别:“btn btn默认值”%>
使用文本
而不是字符串
进行全文搜索。在您的模型中,请尝试:
searchable do
text :title
text :author
text :description
end
如果该语法失败,这将起作用
searchable do
text :title, :author, :description
end
最后,reindex看起来已经修复了它:
bundle exec rake sunspot:solr:reindex
而不是string
使用text
,因此它将是全文搜索。在您的模型中,请尝试:
searchable do
text :title
text :author
text :description
end
如果该语法失败,这将起作用
searchable do
text :title, :author, :description
end
最后,一个reindex似乎已经修复了它:
bundle exec rake sunspot:solr:reindex
我已经尝试过了,行为完全相同。我还是没有结果。是否验证solr服务器正在运行bundle-exec-rake-sunspot:solr:start
也许可以尝试重新索引:bundle-exec-rake-sunspot:solr:reindex
。我想我快疯了。我至少做了10次,但都没用。在你的评论之后,我再次尝试重新索引,现在它工作了。。。谢谢你的帮助。我已经试过了,行为也完全一样。我还是没有结果。是否验证solr服务器正在运行bundle-exec-rake-sunspot:solr:start
也许可以尝试重新索引:bundle-exec-rake-sunspot:solr:reindex
。我想我快疯了。我至少做了10次,但都没用。在你的评论之后,我再次尝试重新索引,现在它工作了。。。谢谢你的帮助。