solr之创建core(搜索核心,包括索引和数据)的方法

我的solrhome为D:solrHomesolr

step1:进入solrHome会看到collection1文件夹,创建该文件夹的副本,重命名为product

进入product文件夹,进入data文件夹,删掉里面的两个目录。

step2:好了,然后来开始创建索引了。

前提,进入tomcat中webapps的solr项目的web.xml中设置solrHome地址

<env-entry>
   <env-entry-name>solr/home</env-entry-name>
   <env-entry-value>D:练习Java练习WEBSearchsolr</env-entry-value>
   <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>

step3:

首先,core selection 选择product

然后,进入product的conf文件夹的schema.xml中加入:


   <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
   <field name="productName" type="string" indexed="false" stored="true" omitNorms="true"/>
   <field name="brandId" type="int" indexed="false" stored="true"/>
   <field name="brandName" type="string" indexed="false" stored="true" omitNorms="true"/>
   <field name="categoryName" type="string" indexed="false" stored="false" multiValued="true"/>
   <field name="price" type="double" indexed="false" stored="true" multiValued="false"/>
   <field name="text" type="text_general" indexed="true" stored="true" multiValued="true"/>
   
   
    <dynamicField name="*_i"  type="int"    indexed="true"  stored="true"/>

   <uniqueKey>id</uniqueKey>

      <copyField source="productName" dest="text"/>
      <copyField source="brandId" dest="text"/>
      <copyField source="categoryName" dest="text"/>

     <filedType>相关的不作修改。

step4:

然后,点击documents,选择xml类型向文本框中输入:

<doc>

<field name="id" >001</field>

<field name="productName">黑色墨镜</field>

<field name="brandId">00908</field>

<field name="brandName">很牛逼</field>

<field name="categoryName">装逼系列</field>

<field name="price">123</field>

<field name="text">茶叶蛋价格</field>

</doc>

然后提交,即可创建索引。

step5:query-> 可以设置查询条件   text:墨镜  

然后可以看到查询结果

原文地址:https://www.cnblogs.com/CooderIsCool/p/4757771.html