Solr

2019-10-09  本文已影响0人  灬哆啦A梦不吃鱼

solr简介

Solr是Apache下的一个顶级开源项目,采用Java开发,它是基于Lucene的全文搜索服务器。Solr提供了比Lucene更为丰富的查询语言,同时实现了可配置、可扩展,并对索引、搜索性能进行了优化

solr安装

~$ ls solr*
solr-7.5.0.zip

~$ unzip -q solr-7.5.0.zip

~$ cd solr-7.5.0/

创建collection(索引的逻辑概念)

这个时候,一个两个节点的solr集群就已经启动完成,solr依靠zookeeper协调管理各个节点,solr会默认启动一个嵌套的zookeeper,启动完成后,会提示你创建集合,熟悉lucene的可以理解为创建document,用来创建数据的索引

 Now let's create a new collection for indexing documents in your 2-node cluster.
  Please provide a name for your new collection: [gettingstarted]

我这里输入techproducts,和官网一致

How many shards would you like to split techproducts into? [2]

这里默认值为2,为了让索引均匀的分布再每个节点上

 How many replicas per shard would you like to create? [2]

这里输入所以备份数量

Please choose a configuration for the techproducts collection, available options are:
_default or sample_techproducts_configs [_default]  

输入配置文件夹名称,主要的配置文件有schema.xml和solrconfig.xml,并在solr-7.5.0\server\solr\configsets文件夹下创建相应的文件夹

Uploading /solr-7.5.0/server/solr/configsets/_default/conf for config techproducts to ZooKeeper at localhost:9983

  Connecting to ZooKeeper at localhost:9983 ...
  INFO  - 2017-07-27 12:48:59.289; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready
  Uploading /solr-7.5.0/server/solr/configsets/sample_techproducts_configs/conf for config techproducts to ZooKeeper at localhost:9983

  Creating new collection 'techproducts' using command:
  http://localhost:8983/solr/admin/collections?action=CREATE&name=techproducts&numShards=2&replicationFactor=2&maxShardsPerNode=2&collection.configName=techproducts

  {
  "responseHeader":{
      "status":0,
      "QTime":5460},
  "success":{
      "192.168.0.110:7574_solr":{
      "responseHeader":{
          "status":0,
          "QTime":4056},
      "core":"techproducts_shard1_replica_n1"},
      "192.168.0.110:8983_solr":{
      "responseHeader":{
          "status":0,
          "QTime":4056},
      "core":"techproducts_shard2_replica_n2"}}}

  Enabling auto soft-commits with maxTime 3 secs using the Config API

  POSTing request to Config API: http://localhost:8983/solr/techproducts/config
  {"set-property":{"updateHandler.autoSoftCommit.maxTime":"3000"}}
  Successfully set-property updateHandler.autoSoftCommit.maxTime to 3000

 SolrCloud example running, please visit: http://localhost:8983/solr

至此,solr创建techproduct已经完成,可以访问solr的管理界面http://localhost:8983/solr,接下来可以向solr添加需要搜索的数据

Linux/Mac:

solr-7.5.0:$ bin/post -c techproducts example/exampledocs/*

windows:

 C:\solr-7.5.0> java -jar -Dc=techproducts -Dauto example\exampledocs\post.jar example\exampledocs\*

example\exampledocs下的文件是solr提供测试演示的文档,正式使用的时候可以是我们自己的所需要分析的数据

  SimplePostTool version 5.0.0
  Posting files to [base] url http://localhost:8983/solr/techproducts/update...
  Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
  POSTing file books.csv (text/csv) to [base]
  POSTing file books.json (application/json) to [base]/json/docs
  POSTing file gb18030-example.xml (application/xml) to [base]
  POSTing file hd.xml (application/xml) to [base]
  POSTing file ipod_other.xml (application/xml) to [base]
  POSTing file ipod_video.xml (application/xml) to [base]
  POSTing file manufacturers.xml (application/xml) to [base]
  POSTing file mem.xml (application/xml) to [base]
  POSTing file money.xml (application/xml) to [base]
  POSTing file monitor.xml (application/xml) to [base]
  POSTing file monitor2.xml (application/xml) to [base]
  POSTing file more_books.jsonl (application/json) to [base]/json/docs
  POSTing file mp500.xml (application/xml) to [base]
  POSTing file post.jar (application/octet-stream) to [base]/extract
  POSTing file sample.html (text/html) to [base]/extract
  POSTing file sd500.xml (application/xml) to [base]
  POSTing file solr-word.pdf (application/pdf) to [base]/extract
  POSTing file solr.xml (application/xml) to [base]
  POSTing file test_utf8.sh (application/octet-stream) to [base]/extract
  POSTing file utf8-example.xml (application/xml) to [base]
  POSTing file vidcard.xml (application/xml) to [base]
  21 files indexed.
  COMMITting Solr index changes to http://localhost:8983/solr/techproducts/update...
  Time spent: 0:00:00.822

到这里,我们的solr加入了分析的数据,并且solr会根据文件的特性,生成默认的field

小试牛刀

solr提供界面进行搜索,操作简单,同事提供接口对外进行搜索,这里展示接口的方式搜索

上一篇 下一篇

猜你喜欢

热点阅读