我对solr不太熟悉.我成功安装了solr.它使用的是码头网络服务器.我的solr版本是4.10.3.管理员页面不受密码保护.任何人都可以访问它.我想在solr admin上应用paaword.我该怎么办?
我有一个带有searchable块的模型,如下所示:
class Contact < ActiveRecord::Base
searchable do
text :contact_name, :company_name, :contact_email
end
end
Run Code Online (Sandbox Code Playgroud)
在控制器的index操作中,我正在调用Contact.new,它在页面上给出了一条错误消息,该消息当前正在我们的临时服务器上运行:
未定义的方法`searchable'用于#<Class:0xce0bf80>
堆栈跟踪searchable通过Contact.new控制器中的线指向模型中的块.
当我在本地(网页或控制台)或通过Staging服务器上的控制台运行代码时,此错误不会出现 - 仅在Staging网页上.
Solr服务在Staging服务器上正常运行,并且数据已成功编制索引.关于为什么它不在舞台上打球的任何理论都将被接受.
编辑
在回答Nick的问题时,Gemfile只有Sunspot的这一行: gem 'sunspot_rails'
对于Gemfile.lock,这些是我能看到的包含Sunspot或Solr引用的所有行:
GEM
rsolr (0.12.1)
builder (>= 2.1.2)
sunspot (1.2.1)
escape (= 0.0.4)
pr_geohash (~> 1.0)
rsolr (= 0.12.1)
sunspot_rails (1.2.1)
nokogiri
sunspot (= 1.2.1)
DEPENDENCIES
sunspot_rails
Run Code Online (Sandbox Code Playgroud) 使用Passenger,Capistrano,nginx和MySQL将我的rails 3.0.10应用程序部署到Ubuntu 10.04服务器时遇到了很多麻烦(而apache2则更麻烦).将rake降级到0.8.7之后它终于正常工作,但现在Sunspot/Solr在我的开发环境中不起作用.sunspot_solr服务器正在运行,我可以获取服务器的URL,并通过浏览器连接到它.该网址与sunspot.yml中的网址相同.我不知道我做了什么导致了这个问题.我之前遇到过与太阳黑子相同的问题(在降级rake之前).然后它突然又开始工作了.我不知道为什么......我试过两个版本的太阳黑子(1.2.1和1.3.0).两者都提前工作,但现在不再工作了.
这是我收到的错误消息:
SocketError (getaddrinfo: Name or service not known):
app/models/resource.rb:128:in `text_search'
app/controllers/search_controller.rb:21:in `index'
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (161.6ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (168.9ms)
Run Code Online (Sandbox Code Playgroud)
控制器有点乱,所以我只包括相关部分:
@criterion = params[:criterion]
@sort_direction = params[:sort_direction]
if @criterion && @sort_direction
session["sort_search"] = @criterion + "|" + @sort_direction
elsif session["sort_search"]
@criterion = session["sort_search"].split("|")[0]
@sort_direction = session["sort_search"].split("|")[1]
else
@criterion = "updated_at"
@sort_direction = "desc"
end
@search = Resource.text_search(session[:search_params] || "", current_user, @criterion, @sort_direction)
@resources = @search.results
Run Code Online (Sandbox Code Playgroud)
我没有更改控制器中的任何内容,因为它正在工作.
我的gemfile:
source 'http://rubygems.org'
gem 'rake'
gem 'rails', '3.0.10' …Run Code Online (Sandbox Code Playgroud) 希望每个人都很好,做得好!我陷入一个奇怪的问题,我正在寻找你的输入.
我的问题是:
使用Capistrano在Production上部署我的应用程序后,当我进行solr重新索引时,它给出了以下错误:
$ bundle exec rake sunspot:reindex --trace
** Invoke sunspot:reindex (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute sunspot:reindex
Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile
rake aborted!
RSolr::Error::Http - 404 Not Found
Error: Not Found
Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete>query>type:OccupationData</query></delete>"
Backtrace: /data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:268:in `adapt_response'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:175:in `execute'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive'
(eval):2:in `post'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:67:in `update'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:131:in `delete_by_query'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/sunspot-1.3.3/lib/sunspot/indexer.rb:55:in `remove_all'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/sunspot-1.3.3/lib/sunspot/session.rb:181:in `block in remove_all'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/sunspot-1.3.3/lib/sunspot/session.rb:181:in `each'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/sunspot-1.3.3/lib/sunspot/session.rb:181:in `remove_all'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/sunspot-1.3.3/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `remove_all'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:268:in `adapt_response'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:175:in `execute'
/data/APP_NAME/shared/bundled_gems/ruby/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in …Run Code Online (Sandbox Code Playgroud) 我正在将我的应用程序升级到Rails 4,现在得到了我的rails服务器,以及太阳黑子solr,经过大量的修补,运行后,我可以访问Solr管理页面.但是,当我尝试从我的rails开发应用程序访问solr进行搜索或索引时,我收到以下错误
RSolr::Error::Http (RSolr::Error::Http - 404 Not Found
Error: Not Found
Request Data: "fq=type%3AMatch&fq=date_in_utc_d%3A%7B2013%5C-11%5C-29T21%5C%3A00%5C%3A00Z+TO+%2A%7D&fq=approval__s%3AAPPROVED&sort=date_d+asc&q=london&fl=%2A+score&qf=caption_text%5E10+city_name_text%5E10+team_name_text%5E10+&defType=edismax&start=0&rows=30"
Backtrace: /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/rsolr-1.0.9/lib/rsolr/client.rb:268:in `adapt_response'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/rsolr-1.0.9/lib/rsolr/client.rb:175:in `execute'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot_rails-2.1.0/lib/sunspot/rails/solr_instrumentation.rb:16:in `block in send_and_receive_with_as_instrumentation'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/notifications.rb:159:in `block in instrument'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.1/lib/active_support/notifications.rb:159:in `instrument'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot_rails-2.1.0/lib/sunspot/rails/solr_instrumentation.rb:15:in `send_and_receive_with_as_instrumentation'
(eval):2:in `post'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot-2.1.0/lib/sunspot/search/abstract_search.rb:45:in `execute'
/Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/sunspot-2.1.0/lib/sunspot/session.rb:59:in `search'):
<a href="txmt://open?url=file:///Users/bashar/rails-projects/myapp/app/models/match.rb&line=474&column=1">app/models/match.rb:474:in `upcoming_games'</a>
<a href="txmt://open?url=file:///Users/bashar/rails-projects/myapp/app/controllers/tickets_controller.rb&line=34&column=1">app/controllers/tickets_controller.rb:34:in `search'</a>
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.4ms)
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.8ms)
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered /Users/bashar/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.3ms)
Run Code Online (Sandbox Code Playgroud)
这是sunspot.yml文件.
production:
solr:
hostname: ENV['WEBSOLR_URL']
port: 80
log_level: WARNING
path: /solr/production
# read_timeout: 2
# open_timeout: 0.5 …Run Code Online (Sandbox Code Playgroud) ruby-on-rails sunspot sunspot-rails sunspot-solr ruby-on-rails-4
系统插入新记录db并更新solr索引时经常引发此异常,有没有人遇到同样的问题?怎么避免呢?
Mar 29, 2012 6:26:59 PM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/update params={wt=ruby} status=0 QTime=110977
Mar 29, 2012 6:26:59 PM org.apache.solr.common.SolrException log
SEVERE: org.mortbay.jetty.EofException
at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:791)
at org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:569)
at org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:1012)
at sun.nio.cs.StreamE`enter code here`ncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at org.apache.solr.common.util.FastWriter.flush(FastWriter.java:115)
at org.apache.solr.servlet.SolrDispatchFilter.writeResponse(SolrDispatchFilter.java:344)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:265)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用Sunspot来索引和搜索Rails项目中的几个模型,我需要根据模型与模型的HABTM关联来限制结果Department.这是因为用户可能没有权限查看所有部门的记录,因此不应返回这些部门的结果.
以下是两个模型的重要部分:
class Message < ActiveRecord::Base
has_many :comments, dependent: :destroy
has_and_belongs_to_many :departments
searchable do
text :title, :body
text :comments do
comments.map(&:body)
end
date :created_at
integer :department_ids, using: :department_ids, references: Department, multiple: true
end
end
class Document < ActiveRecord::Base
has_and_belongs_to_many :departments
searchable do
text :name
date :created_at
integer :department_ids, using: :department_ids, references: Department, multiple: true
end
end
Run Code Online (Sandbox Code Playgroud)
这是搜索控制器代码:
class SearchController < ApplicationController
def index
# These arrays are created here for the sake of this example
document_permitted_departments = [1, …Run Code Online (Sandbox Code Playgroud) 我正在调试我的Solr架构,我希望看到标记特定字段的结果.
举一个简单的例子,如果我有:
<fieldType name="text" class="solr.TextField" omitNorms="false">
<analyzer>
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StandardFilterFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.PorterStemFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="15" side="front"/>
</analyzer>
</fieldType>
Run Code Online (Sandbox Code Playgroud)
我用一个值索引了一个字段"Hello, worlds!",我希望看到以下内容:
hello world he el ll lo hel ell llo hell ello hello wo or rl ld wor orl rld worl orld
确保所有内容都按照我的设想进行标记化.
这有可能吗?
我使用PuTTy连接到我们的Ubuntu生产服务器.
我想使用Solr重新索引特定的模型.我想从Rails控制台运行reindex命令,即Modelname.reindex(因为它似乎比rake任务运行得更快.)
但是,我们正在查看大量数据,这种索引预计需要几个小时.
我希望能够在rails控制台中启动此任务,即使退出PuTTy,它也应该继续运行.这该怎么做?
Linux:关闭SSH客户端建议nohup 后阻止后台进程停止,但我不知道是否/如何使用rails控制台.
我已经实现了solr搜索我的rails应用程序.我已经将搜索字段编入索引,并且工作正常.现在我想在搜索时排除一个名为Title的特定字段.如何在搜索时跳过此特定字段.是否还有索引文本字段的排除选项.
searchable do
integer :id
boolean :searchable
boolean :premium
string :status
time :updated_at
time :created_at
###################################################
# Fulltext search fields
text :title
text :summary
text :skills
end
Run Code Online (Sandbox Code Playgroud)
在这里,我如何只从全文搜索中删除标题字段
profiles = Profile.search do |s|
s.fulltext @selected_filters[:query][:value] , exclude => :title
end
Run Code Online (Sandbox Code Playgroud)
有没有办法这样做?请帮忙