Rails 4 - Sunspot 在所有查询中返回空结果
Rails 4 - Sunspot returning empty results on all queries
我有一个 Person 模型,我希望对其执行搜索。
class Person < ActiveRecord::Base
searchable do
text :first_name, :last_name, :boost => 2
text :email, :phone
end
end
我已经从 people_controller 中删除了搜索功能,因为从长远来看 运行 我希望增加搜索所有模型的范围。这是搜索控制器
class SearchController < ApplicationController
def index
@people = Person.search do
fulltext params[:search]
end
@results = @people.results
end
end
我正在使用 UJS 在页面的搜索窗格中呈现搜索结果。目前 search/index.js.erb 附加上述 @results 变量的调试输出。
$('#search-results').empty();
$('#search-results').append('<%= j debug @results %>');
我尝试的每个查询 returns 以下结果。
--- !ruby/array:Sunspot::Search::PaginatedCollection
internal: []
ivars:
:@current_page: 1
:@per_page: 30
:@total_count: 0
并且在 rails 控制台中显示以下内容。
Parameters: {"utf8"=>"✓", "search"=>"Sabrina", "commit"=>"Go"}
SOLR Request (4.7ms) [ path=select parameters={fq: ["type:Person"], q: "Sabrina", fl: "* score", qf: "first_name_text last_name_text email_text phone_text", defType: "edismax", start: 0, rows: 30} ]
重要的是要注意这个查询是 copy/pasted 来自数据库中的一个人。最初我担心错误容忍度不允许甚至很小的拼写错误。
这开始变得非常令人沮丧,到目前为止,我已经删除并重新安装了最新的 JDK,并重新启动了我的机器。在这一点上,我还没有看到任何错误或失败的依赖项等。有一个可能的例外:当我 运行 rake sunspot:solr:reindex
我在终端中只得到以下内容
Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile
我的问题是:我做错了什么?
试试这个
class SearchController < ApplicationController
def index
@people = Sunspot.search(Person) do
fulltext params[:search]
end
@results = @people.results
end
end
我有一个 Person 模型,我希望对其执行搜索。
class Person < ActiveRecord::Base
searchable do
text :first_name, :last_name, :boost => 2
text :email, :phone
end
end
我已经从 people_controller 中删除了搜索功能,因为从长远来看 运行 我希望增加搜索所有模型的范围。这是搜索控制器
class SearchController < ApplicationController
def index
@people = Person.search do
fulltext params[:search]
end
@results = @people.results
end
end
我正在使用 UJS 在页面的搜索窗格中呈现搜索结果。目前 search/index.js.erb 附加上述 @results 变量的调试输出。
$('#search-results').empty();
$('#search-results').append('<%= j debug @results %>');
我尝试的每个查询 returns 以下结果。
--- !ruby/array:Sunspot::Search::PaginatedCollection
internal: []
ivars:
:@current_page: 1
:@per_page: 30
:@total_count: 0
并且在 rails 控制台中显示以下内容。
Parameters: {"utf8"=>"✓", "search"=>"Sabrina", "commit"=>"Go"}
SOLR Request (4.7ms) [ path=select parameters={fq: ["type:Person"], q: "Sabrina", fl: "* score", qf: "first_name_text last_name_text email_text phone_text", defType: "edismax", start: 0, rows: 30} ]
重要的是要注意这个查询是 copy/pasted 来自数据库中的一个人。最初我担心错误容忍度不允许甚至很小的拼写错误。
这开始变得非常令人沮丧,到目前为止,我已经删除并重新安装了最新的 JDK,并重新启动了我的机器。在这一点上,我还没有看到任何错误或失败的依赖项等。有一个可能的例外:当我 运行 rake sunspot:solr:reindex
我在终端中只得到以下内容
Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile
我的问题是:我做错了什么?
试试这个
class SearchController < ApplicationController
def index
@people = Sunspot.search(Person) do
fulltext params[:search]
end
@results = @people.results
end
end