solr建立核心库

转自http://blog.csdn.net/u011936655/article/details/51960005

在本节中,我们将告诉你如何配置的核心/集合作为Solr实例,以及如何定义的字段。Apache Solr附带称为无模式模式的选项。这个选项允许用户构建有效的架构,而无需手动编辑模式文件。但是,在这个例子中,我们将使用架构配置理解Solr的内部。

3.1建立核心(core)

当Solr的服务器在独立模式下启动的配置称为核心,当它在SolrCloud模式启动的配置称为集合。在这个例子中,我们将有关独立服务器和核心讨论。我们将在以后再讨论SolrCloud。首先,我们需要创建一个核心的索引数据。Solr的创建命令有以下选项:

  1. -c <name> -要创建的核心或集合的名称(必需)。
  2. -d <confdir> -配置目录,在SolrCloud模式非常有用。
  3. -n <configName> -配置名称。这将默认为核心或集合的名称。
  4. -p <port> -本地Solr的实例的端口发送create命令; 默认脚本试图通过寻找运行Solr的实例来检测端口。
  5. -s <shards> -Number of shards to split a collection into, default is 1.
  6. -rf <replicas> -集合中的每个文件的份数。默认值是1。

在这个例子中,我们将使用的核心名称和配置目录-d参数-c参数。对于所有其它参数我们使用默认设置。

现在在命令窗口浏览 solr-5.0.0\bin文件夹,并发出以下命令。

solr create -c jcg -d basic_configs

我们可以看到在命令窗口中下面的输出。

Creating new core 'jcg' using command:

http://localhost:8983/solr/admin/cores?action=CREATE&name=jcg&instanceDir=jcg

 {

 "responseHeader":{

 "status":0,

 "QTime":663},

 "core":"jcg"}

 

现在我们导航到以下网址,我们可以看到JCG核心被填充在核心选择器上。还可以看到核心的统计信息。

http://localhost:8983/Solr

Solr的核心JCG

3.2修改Schema.xml文件

我们需要修改schema.xml中文件的文件夹下,server\solr\jcg\conf包含的字段。我们将使用随Solr的安装索引附带的示例文件“books.csv”之一。该文件所在的文件夹下  的solr-5.0.0\example\exampledocs

现在,我们定位到该文件夹  server\solr目录。你会看到一个名为JCG的文件夹被创建。子文件夹conf和data分别拥有核心的配置和索引的数据。

现在编辑\server\solr\jcg\conf\server\solr\jcg\conf\managed-schema文件,设置唯一元素后添加以下内容。

schema.xml

  1. <uniqueKey>id</uniqueKey>  
  2.   
  3. <!-- Fields added for books.csv load-->  
  4.   
  5. <field name="cat" type="text_general" indexed="true" stored="true"/>  
  6.   
  7. <field name="name" type="text_general" indexed="true" stored="true"/>  
  8.   
  9. <field name="price" type="tdouble" indexed="true" stored="true"/>  
  10.   
  11. <field name="inStock" type="boolean" indexed="true" stored="true"/>  
  12.   
  13. <field name="author" type="text_general" indexed="true" stored="true"/>  

  

我们已经设置了属性索引为true。这指定字段用于索引和记录可以使用索引进行检索。该值设置为false将只存储领域,但不能进行查询。

另外请注意另一个属性stored并将其设置为true。这指定字段被存储,并且可以在输出被返回。将此字段设置为假将使字段唯一索引,并且不能在输出进行检索。

我们已经分配给存在于此处的“books.csv”文件中的字段的类型。在CSV文件“ID”第一场由索引Schema.xml文件的唯一键自动元素的照顾。如果你注意,我们已经略过字段series_t,sequence_i和genre_s未做任何条目。但是,当我们执行索引时,所有这些字段都被索引且没有任何问题。如果你想知道这种情况需要在Schema.xml文件的dynamicField部分一探究竟。

schema.xml

<dynamicField name="*_i" type="int" indexed="true" stored="true"/>

<dynamicField name="*_is" type="ints" indexed="true" stored="true"/>

<dynamicField name="*_s" type="string" indexed="true" stored="true" />

<dynamicField name="*_ss" type="strings" indexed="true" stored="true"/>

<dynamicField name="*_l" type="long" indexed="true" stored="true"/>

<dynamicField name="*_ls" type="longs" indexed="true" stored="true"/>

<dynamicField name="*_t" type="text_general" indexed="true" stored="true"/>

<dynamicField name="*_txt" type="text_general" indexed="true" stored="true"/>

<dynamicField name="*_b" type="boolean" indexed="true" stored="true"/>

<dynamicField name="*_bs" type="booleans" indexed="true" stored="true"/>

<dynamicField name="*_f" type="float" indexed="true" stored="true"/>

<dynamicField name="*_fs" type="floats" indexed="true" stored="true"/>

<dynamicField name="*_d" type="double" indexed="true" stored="true"/>

<dynamicField name="*_ds" type="doubles" indexed="true" stored="true"/>

 

既然我们已经修改了配置,我们必须停止和启动服务器。要做到这一点,我们需要通过命令行发出从bin目录下面的命令。

Solr  stop -all

服务器将停止现在。现在启动服务器问题从bin目录中通过命令行运行以下命令。

Solr start

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值