Solr学习

 一、什么是Solr

  Solr是一个开源搜索平台,用于构建搜索应用程序。 它建立在Lucene(全文搜索引擎)之上。 Solr是企业级的,快速的和高度可扩展的。 使用Solr构建的应用程序非常复杂,可提供高性能。

  总之,Solr是一个可扩展的,可部署,搜索/存储引擎,优化搜索大量以文本为中心的数据

 

  Solr相比关系型数据库(如MySQL)的优势:

    ①:Solr本身也可以看成数据库,(no sql类型),但它比数据库搜索速度更快

    ②:数据库本身不能实现分词效果,而只能使用模糊查询,但是模糊查询非常低效,查询速度比较慢,由于在实际生活中,一般搜索是用的比较多的,这样数据库压力自然就很大,所以我们就让供专业的solr来做搜索功能

        

二、下载安装

  1、下载 solr-7.7.3.tgz :https://www.apache.org/dyn/closer.lua/lucene/solr/7.7.3/solr-7.7.3.tgz?action=download

  2、解压 solr-7.7.3.tgz ,目录结构如下:

 

 

  3、启动solr

    ./bin/solr start -e cloud

    ①:

      Welcome to the SolrCloud example!

      This interactive session will help you launch a SolrCloud cluster on your local workstation.
      To begin, how many Solr nodes would you like to run in your local cluster? (specify 1-4 nodes) [2]:

      按照提示输入运行的节点数,默认的节点数为2,回车

    ②:接着按照提示输入每个节点运行的端口,按照默认的端口即可

      INFO - 2022-03-01 21:45:27.850; org.apache.solr.common.cloud.ConnectionManager; zkClient has connected
      INFO - 2022-03-01 21:45:27.864; org.apache.solr.common.cloud.ZkStateReader; Updated live nodes from ZooKeeper... (0) -> (2)
      INFO - 2022-03-01 21:45:27.879; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready

    请注意,两个 Solr 实例已在两个节点上启动。因为我们是在 SolrCloud 模式下开始的,并且没有定义有关外部 ZooKeeper 集群的任何细节,所以 Solr 启动了自己的 ZooKeeper 并将两个节点都连接到它

    ③:节点启动完成之后,系统会提示创建一个用于索引数据的集合

      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]

      询问需要创建多少个副本,副本是用于故障转移的索引的副本,默认值为2即可,回车

    ⑥:Please choose a configuration for the techproducts collection, available options are:

_default or sample_techproducts_configs [_default]

      一个集合必须有一个configSet,它至少包括 Solr 的两个主要配置文件:模式文件(命名为managed-schemaor schema.xml)和solrconfig.xml

      使用默认的sample_techproducts_configs即可,回车

    ⑦:创建集合,并启动Solr

Created collection 'techproducts' with 2 shard(s), 2 replica(s) with config-set 'techproducts'

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 

    ⑧:访问 http://localhost:8983/solr   

 

       Solr 现在将运行两个“节点”,一个在端口 7574 上,一个在端口 8983 上。有一个自动创建techproducts的集合,两个分片,每个分片有两个副本:

 

 

三、Solr文档、字段和模式设计  

  Solr的基本信息单元是文档,文档是一组记录数据。

  schema:

    Solr在schema文件中存储了有关字段类型和预期了解的字段的详细信息

    

  1、动态字段

    动态字段允许 Solr 索引未在schema中明确定义的字段。  

    动态字段与常规字段一样,只是它的名称中带有通配符。在索引文档时,不匹配任何明确定义的字段的字段可以与动态字段匹配      

 

  

  TODO           

 

 

 

 

附录:

  Solr官方网站:https://solr.apache.org/

  Solr官方文档:https://solr.apache.org/guide/7_7/about-this-guide.html

        https://solr.apache.org/guide/solr/latest/getting-started/solr-tutorial.html

  w3cschool solr文档:https://www.w3cschool.cn/solr_doc/

 

END.

posted @ 2022-02-25 10:05  杨岂  阅读(283)  评论(0编辑  收藏  举报