Solr学习、安装与Quick Start
之前用Lucene进行了一些简单的例子,现在安装Solr学习一下。
在mac下,貌似可以直接brew install solr来进行安装。尝试一下。
貌似安装成功了:
==> Summary
🍺 /usr/local/Cellar/solr/6.1.0: 5,968 files, 216.8M, built in 3 minutes 56 seconds
从这个页面能够看到Quick Start文档:
http://lucene.apache.org/solr/quickstart.html
按照上面的说明来一步步操作。
首先cd到solr安装目录:
cd /usr/local/Cellar/solr/6.1.0
然后运行Solr启动命令:
bin/solr start -e cloud -noprompt
能够看到页面中打印出一系列启动的日志:
包括Zookeeper相关: Connecting to ZooKeeper at localhost:9983 ... Uploading /usr/local/Cellar/solr/6.1.0/server/solr/configsets/data_driven_schema_configs/conf for config gettingstarted to ZooKeeper at localhost:9983 最后显示: SolrCloud example running, please visit: http://localhost:8983/solr
然后在浏览器打开 http://localhost:8983/solr ,能够看到管理端界面,说明Solr启动成功!
另外这个时候,在页面 http://localhost:8983/solr/#/gettingstarted/query 也能够看到搜索的界面。现在因为还没有文档和索引,所以即使用"*:*"去搜索全部文档,也是还没有结果,如图:
然后继续按照上面Quick Start的教程,进行下一步。在Solr目录运行命令:
bin/post -c gettingstarted docs/ 报错,说docs这个目录不存在。看了一下,的确在当前安装目录下没有docs这个目录。 所以换了一个目录: bin/post -c gettingstarted examples/ 打印了很多日志,最后显示日志: 305 files indexed. COMMITting Solr index changes to http://localhost:8983/solr/gettingstarted/update... Time spent: 0:00:22.017 应该是建索引完成。
这时候,在刚刚的查询页面 http://localhost:8983/solr/#/gettingstarted/query ,同样使用 "*:*"查询,就可以获得很多结果:
再把查询条件从 "*:*"改成"lucene",就能够得到25条结果(其中用 *和用 *:* 都可以得到1397条结果,貌似都是全部结果):
{ "responseHeader":{ "zkConnected":true, "status":0, "QTime":37, "params":{ "q":"lucene", "indent":"on", "wt":"json", "_":"1476952597488"}}, "response":{"numFound":25,"start":0,"maxScore":7.1965156,"docs":[ { "id":"978-1933988177", "cat":["book", "paperback"], "name":["Lucene in Action, Second Edition"], "author":["Michael McCandless"], "sequence_i":1, "genre_s":"IT", "inStock":[true], "price":[30.5], "pages_i":475, "_version_":1548697679150710784}, { "id":"SOLR1000", "name":["Solr, the Enterprise Search Server"], "manu":["Apache Software Foundation"], "cat":["software", "search"], "features":["Advanced Full-Text Search Capabilities using Lucene", "Optimized for High Volume Web Traffic", "Standards Based Open Interfaces - XML and HTTP", "Comprehensive HTML Administration Interfaces", "Scalability - Efficient Replication to other Solr Search Servers", "Flexible and Adaptable with XML configuration and Schema", "Good unicode support: héllo (hello with an accent over the e)"], "price":[0.0], "popularity":[10], "inStock":[true], "incubationdate_dt":"2006-01-17T00:00:00Z", "_version_":1548697685509275648}, { "id":"/usr/local/Cellar/solr/6.1.0/example/example-DIH/solr/db/conf/lang/stopwords_el.txt", "stream_size":[801], "x_parsed_by":["org.apache.tika.parser.DefaultParser", "org.apache.tika.parser.txt.TXTParser"], "stream_content_type":["text/plain"], "content_encoding":["UTF-8"], "resourcename":["/usr/local/Cellar/solr/6.1.0/example/example-DIH/solr/db/conf/lang/stopwords_el.txt"], "content_type":["text/plain; charset=UTF-8"], "_version_":1548697672428290048}, ......
关闭Solr。使用下面的命令:
bin/solr stop -all
会打印出下面这些日志:
$ bin/solr stop -all Sending stop command to Solr running on port 7574 ... waiting 5 seconds to allow Jetty process 7009 to stop gracefully. Sending stop command to Solr running on port 8983 ... waiting 5 seconds to allow Jetty process 6911 to stop gracefully.
然后localhost:8983就不再能访问。
以上内容,参考 http://lucene.apache.org/solr/quickstart.html
后面,可以对Solr做进一步的学习。