终于把Solr的Multi-Indexes配置出来了

bachue posted @ 2013年9月16日 23:52 in Search Engine with tags apache java tomcat solr elasticsearch sphinx jetty catalina , 4825 阅读

之前由于CodeJam要做搜索引擎相关的功能,而我经过了多个市面上比较流行的搜索引擎的对比之后,最终选择了Solr,主要是Solr在各方面都比较切合需求,DSL的查询语言也足够Easy和Reasonable。唯一的缺陷就是Solr是Java程序,具有很强的Java风格,这种风格对我这样一个Ruby程序员来说非常不适应。这种风格总的来说就是,完全XML配置,必须放在Tomcat或是Jetty中才能使用。

开始的Index配置的还是很成功,参考资料主要是:http://www.gm100861.com/519.html,这是我Google到目前为止我认为最靠谱的一篇文章了。

但是由于我们的搜索需要两个索引,而Solr不像Sphinx或是ElasticSearch天然支持多索引的特性,不过关于Solr的多索引配置的文档依然相当多,手段主要是Multi-indexes, Multi-cores和Multi-collections。我一开始选中了Multi-indexes,按照网上的一些文章一步一步做,试遍了各种方法,但最后全部都失败了。失败原因主要是不了解Tomcat的运行机制,而我出现的错误又很尴尬,访问localhost:8080/solr1出现404错误,没有任何错误消息,完全不知道该怎么办才好了,而且日志既不出现在/var/log里,也没有标准输出,Tomcat自身的错误日志又很多,找了半天,不知道哪个是哪个(后来才知道Tomcat和Ruby程序习惯不一样的地方就是,Tomcat在启动是加载webapp的时候就已经发生错误了,而Ruby程序都是访问时才检测错误,所以我每次在出现404的时候去找错误信息,显然什么都没找到)。再加上Tomcat是Java写的,没有办法通过调试源码来发现错误。后来又尝试了Multi-cores,也是完全不成功。

于是求助于Ruby China@yesmeck给了我一个gist,里面提及了一种简单的依靠调用REST API创建Collection的方法,这种方法真的简单,而且一弄就成功了!然后可以通过localhost:8080/solr/collection{n}/的REST API来指定相应的Collection。但是很奇怪的是,只要我一重启Tomcat,那些自己创建的Collection都会自动丢失,必须重新创建,很无语。网上我也没有找到好的解决方案。虽然如此,我还是用了很久,从CodeJam开始到今天第一次Demo,我还写了个脚本,在每次重启Tomcat后执行用来创建Collection并进行data import,还是蛮方便的。

今天搞完第一次Demo后,我终于稍微松口气,可以再试一次Multi-indexes的配置了,由于做了一个多礼拜的Solr,我对Tomcat和Solr的理解已经开始清晰了。所以第二次做的时候,我不再想之前一样在网上跟各种步骤,而是只看http://www.gm100861.com/519.html这篇我最相信的文章,以及这篇官方文档

在基本做完了所需步骤后,其中Tomcat,随即查看tomcat/logs/catalina.out,经过一个多礼拜的使用,我已经确信这个日志文件综合了Tomcat的各种日志输出。从日志中我很快发现了错误:

java.lang.IllegalArgumentException: Document base /usr/local/apache-tomcat-7.0.42/webapps/solr1 does not exist or is not a readable directory

我按照官方文档在tomcat/conf/Catalina/localhost下创建了solr1.xml和solr2.xml,然后就出现了这个错误。我猜测在Tomcat中创建什么名字的配置文件就代表什么名字的webapp,就像Rails的Convention一样,而不管这个文件里面如何指定了war文件的路径,这点我在之前任何一个Google的搜索结果中都没有看到。随后我在webapps下将solr更名为solr1,并创建了符号链接solr2。为了防止放在目录下的solr.war重新创建solr目录,我把solr.war也改名为solr1.war,同时也创建了符号链接solr2.war。这步完成后,错误信息改为

SEVERE: Error filterStart

这个错误就更人无语了,我按照网上的文章把filter去掉没有起效,把JDK1.7装上去之后还是不行,最后突然看到一个帖子说有可能是哪个必要的jar包找不到,于是立刻想起http://www.gm100861.com/519.html中的最后部分提及了要拷贝一些jar包到指定目录的,而我之前没做这步,完成后重启,访问localhost:8080/solr1和localhost:8080/solr2就都成功了,而且也不会再出现重启后消失的诡异情况。

Liwovosa 说:
2021年5月17日 22:15

I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. 123movies that works

Liwovosa 说:
2021年5月17日 22:18

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. 123movies that works

Judi Casino Online T 说:
2021年6月01日 19:31

Judi casino online terbaik. Dapatkan untung yang besar dan bersiap menjadi milyarder hanya di SlotJawara.org. Situs judi online 24 jam terpercaya - agen judi bola online terpercaya deposit pulsa. Terbesar di Indonesia. Segera kunjungi kami.

Cars in oman 说:
2021年7月20日 20:27

I see some amazingly important and kept up to length of your strength searching for in your on the site

jasa seo indonesia 说:
2021年8月16日 19:15

Concerning a short while ago going your site, the information you actually give on this site includes made it simpler for people considerably. With thanks to get your complete time frame & deliver the results.

smm panel 说:
2021年8月22日 22:58

This particular tools are extremely important to me whenever I require because they help me get the practical analysis of my project completed.

먹튀검증사이트 说:
2021年9月14日 19:41

When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

apple back to school 说:
2022年8月20日 00:06

Apple back to school deal, free Air pods when you buy a MacBook Air or iPad Air. apple education discount 2021. apple back to school sale start Apple back to school 2021 free beats at apple.com/us-hed/shop/back-to-school. Learn more about free delivery and returns. Enjoy 20 per cent off AppleCare+ coverage.2. Learn more about AppleCare+. Free personal engraving. Apple. Back ...

seo service london 说:
2024年2月21日 21:03

 definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter