关于内网开发环境 solr 问题解决办法

因为开发环境的 Oracledocker 容器中运行,并没有太多数据,手动添加公司时牵扯到 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 对比,下面改 solrrails 即可:

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!
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景: 阅读新闻 12C CDB模式下RMAN备份与恢复 [日期:2016-11-29] 来源:Linux社区 作...
    阳屯okyepd阅读 3,642评论 0 7
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,993评论 6 342
  • 最近在做一个项目时,客户要求实现站内全文检索功能,因而接触到Solr这款开源的企业级全文搜索 引擎。官网:http...
    熊颀阅读 1,626评论 0 3
  • 01. 我挺佩服朋友圈里,做微商的人,无论别人怎么反感,他们依旧“走自己的路,让别人去说。” 为了做微商,失去了很...
    汗颜的泥巴阅读 553评论 0 1
  • 时间是个即漫长又飞快的东西,看着似乎是在磨磨蹭蹭磨日子,其实它就在你心烦意乱之中已经悄悄地溜走了,一点儿痕迹都没有...
    香辣豌豆阅读 244评论 0 2