因为开发环境的 Oracle
在 docker
容器中运行,并没有太多数据,手动添加公司时牵扯到 solr
,于是我就清明节一下午时间就着手解决这个问题。下面我把这个解决办法记录在此,首先是一个额外问题的解决办法,如果遇到的话。 ORA-21561: 生成 OID 失败 (OCIError)
这个问题的解决办法如下:
It works at reach $ sudo echo -e "127.0.0.1\t`hostname`" >> /etc/hosts
正文开始,前面过程基本按照 Adding Sunspot search to Rails in 5 minutes or less 这个过程:
It works at reach $ ruby script/generate sunspot
/home/tux/.rvm/gems/ruby-1.8.7-p374@reach/gems/rails-2.1.1/lib/rails_generator/lookup.rb:211:Warning: Gem::SourceIndex#search support for Regexp patterns is deprecated, use #find_name
create config/sunspot.yml
注意和上述 wiki
对比,下面改 solr
为 rails
即可:
It works at reach $ cp `bundle show sunspot_rails`/lib/sunspot/rails/tasks.rb lib/tasks/sunspot.rake
并修改 lib/tasks/sunspot.rake
其中第 50
行代码,例如可改成这样:
all_files = Dir.glob("#{Rails.root}/#{File.join('app', 'models', '*.rb')}")
接下来启动 solr
,建议先删除 ./solr
如果有的话:
It works at reach $ rake sunspot:solr:start
(in /var/www/reach)
Copied default schema.xml to /var/www/reach/solr/conf/schema.xml
Copied default solrconfig.xml to /var/www/reach/solr/conf
Copied default elevate.xml to /var/www/reach/solr/conf
Copied default spellings.txt to /var/www/reach/solr/conf
Copied default stopwords.txt to /var/www/reach/solr/conf
Copied default synonyms.txt to /var/www/reach/solr/conf
上述敲完又生成了 ./solr
,再修改 /var/www/reach/solr/conf/schema.xml
,在适当位置加上一行:
我第一次是把代码中所有 *_textp
给注掉了,所以改动比较多,不值得分享,现在我又发现了这个办法。
最后由于毕竟是开发环境,需要注掉几个文件,gird_file.rb
还有 aliyun
相关,注意,注释掉文件需要保留住 class SomeClass ... end
,只注掉类里面的或者模块里面的东西即可。
最后可以把所有 solr
相关的 include ... if ENV["RAILS_ENV"] == 'production'
后面的条件去掉了,接下来可以成功 reindex
了。
It works at reach $ rake sunspot:solr:reindex
(in /var/www/reach)
Start index at Fri Apr 08 00:00:28 +0800 2016...
Total 1 records to index.
50|0,Finished index at Fri Apr 08 00:00:28 +0800 2016, last 0.383941 seconds!
Start index at Fri Apr 08 00:00:28 +0800 2016...
Total 1 records to index.
50|0,Finished index at Fri Apr 08 00:00:28 +0800 2016, last 0.139266 seconds!
Start index at Fri Apr 08 00:00:28 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:28 +0800 2016, last 0.144126 seconds!
Start index at Fri Apr 08 00:00:28 +0800 2016...
Total 2 records to index.
50|0,Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.180567 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.055592 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 2 records to index.
50|0,Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.142087 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.051341 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.16026 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.04935 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.057592 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 1 records to index.
50|0,Finished index at Fri Apr 08 00:00:29 +0800 2016, last 0.094946 seconds!
Start index at Fri Apr 08 00:00:29 +0800 2016...
Total 1 records to index.
50|0,Finished index at Fri Apr 08 00:00:30 +0800 2016, last 0.245078 seconds!
Start index at Fri Apr 08 00:00:30 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:30 +0800 2016, last 0.030967 seconds!
Start index at Fri Apr 08 00:00:30 +0800 2016...
Total 2 records to index.
50|0,Finished index at Fri Apr 08 00:00:30 +0800 2016, last 0.25676 seconds!
Start index at Fri Apr 08 00:00:30 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:30 +0800 2016, last 0.022504 seconds!
Start index at Fri Apr 08 00:00:30 +0800 2016...
Total 2 records to index.
50|0,Finished index at Fri Apr 08 00:00:31 +0800 2016, last 0.846743 seconds!
Start index at Fri Apr 08 00:00:31 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:31 +0800 2016, last 0.021217 seconds!
Start index at Fri Apr 08 00:00:31 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:31 +0800 2016, last 0.023281 seconds!
Start index at Fri Apr 08 00:00:31 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:31 +0800 2016, last 0.020052 seconds!
Start index at Fri Apr 08 00:00:31 +0800 2016...
Total 0 records to index.
Finished index at Fri Apr 08 00:00:31 +0800 2016, last 0.016412 seconds!