“This is the 8th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

1. Integrate Solr service with Tomcat

Tomcat installation and running environment

  • Jdk: 1.8 and above
  • Solr: 7.1
  • Web server: tomcat 8 (change port 8081, if there is only one Tomcat, can not change, default is 8080; If there are multiple Tomcats, you need to change the port number to prevent conflicts. If one Tomcat has environment variables configured, the others need to be configured to use, or none at all.

integration

Step 1: F: solr\solr-7.1.0\server\ solr-webApp \webapp put the contents in the solr folder under F: solr\apache-tomcat-8.0.41\webapps (solr folder needs to be created).

F: solr\solr-7.1.0\server\lib copy all jar packages INF: solr\apache-tomcat-8.0.41\webapps\solr\ web-inf \lib, including ext folder.

Step 3: Put the log4j.properties file under F: solr\solr-7.1.0\server\ Resources into the new class under F: solr\apache-tomcat-8.0.41\webapps\solr\ web-INF \ Es folder. Step 4: Create a solr_HOME folder for configuring the files that the SOLr server wants to respond to. Copy the contrib and dist folders under F:\solr\solr-7.1.0 and everything under F:\solr\solr-7.1.0\server\solr to the new directory solr_home. In the solr_HOME directory, create a demo_core folder to add Core selection classes to the Slor page and set the search mode.

Note: Modify the F: solr solr_home demo_core conf solrconfig.xml file

Note: modify the web.xml file INF: solr\apache-tomcat-8.0.41\webapps\solr\ web-inf \

Comment this out

Start Tomcat, and the Solr page is displayed

Go to http://localhost:8081/solr/index.html

Derivative data, configure Chinese word segmentation

Copy all jar packages in F:\solr\solr-7.1.0\contrib\analysis-extras\lucene-libs and two packages in F:\solr\solr-7.1.0\dist to F:\solr\apache-tomc At-8.0.41 \webapps\solr\ web-INF \lib

Add the middle classifier configuration to managed-schema in F:\solr\solr_home\core_demo\conf

<! -- ChineseAnalyzer -->

    <fieldType name="solr_cnAnalyzer" class="solr.TextField" positionIncrementGap="100">

      <analyzer type="index">

        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>

      </analyzer>

      <analyzer type="query">

        <tokenizer class="org.apache.lucene.analysis.cn.smart.HMMChineseTokenizerFactory"/>

      </analyzer>

    </fieldType>
Copy the code

Solrconfig. XML adds requestHandler configuration. Data-config. XML configures database connection information, SQL, and query result mapping fields.

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">

    <lst name="defaults">

    <str name="config">data-config.xml</str>

    </lst>

</requestHandler>
Copy the code

Therefore, you need to create data-config. XML file in the statistics directory, and the corresponding attributes of the mapping file will not be described in detail


      

<dataConfig>

  <dataSource type="JdbcDataSource"

              driver="com.mysql.jdbc.Driver"

              url="jdbc:mysql://localhost:3306/solr"

              user="root"

              password="root"/>

  <document>
<! Alter table name = 'entity';
<entity name="products"  query="select pid,pname,catalog_name,price,description,picture from products ">

 <field column="pid" name="id"/>  

 <field column="pname" name="prod_pname"/>  

 <field column="catalog_name" name="prod_catalog_name"/>  

 <field column="price" name="prod_price"/>  

 <field column="description" name="prod_description"/>  

 <field column="picture" name="prod_picture"/>  

</entity>

  </document>

</dataConfig>
Copy the code

Start the service, add data, query the demo.

Query syntax: 1. Q Queries all keywords using *:*. Multiple conditions can be: associated with AND OR OR

Filter query (fQ) : product_price:[1 TO 20]