因為開發環境的 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
,在適當位置加上一行:
<dynamicField name="*_textp" stored="true" type="text" multiValued="true" indexed="true"/>
我第一次是把代碼中所有 *_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!