Solr search engine - Configure the data source by mysql

First, prepare the database
data table structure

CREATE TABLE `app` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`app_name` varchar(255) NOT NULL DEFAULT '',
`score` decimal(10,5) NOT NULL DEFAULT '0.00000',
`downLoadNum` int(10) NOT NULL DEFAULT '0',
`top` int(10) NOT NULL DEFAULT '0',
`type` int(10) NOT NULL DEFAULT '1',
`update_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
1
2
3
4
5
6
7
8
9
10
生成一些测试数据

 

Because we need to use mysql as a data source, we need to increase the use of the jar package for mysql

> CD Server / solr-the webapp / the webapp / the WEB-INF / lib /
> wget http://pic.w-blog.cn/mysql-connector-java.jar
. 1
2
II-Core increase solr
the PS: Here basis solr command to start the program was not based on tomcat configure subsequent cloud cluster will be configured to use tomcat into

 

Try increasing the core will be prompted to find a configuration, a copy of the default configuration file

 

> -R & lt Server CP / Solr / configsets / Server the _default / Solr / new_core
. 1
, add the following configuration in solrconfig.xml, add about 680 line positions, SearchHandler above configuration:

> vim server/solr/new_core/conf/solrconfig.xml

<!-- Request Handlers
http://wiki.apache.org/solr/SolrRequestHandler
Incoming queries will be dispatched to a specific handler by name
based on the path specified in the request.

If a Request Handler is declared with startup="lazy", then it will
not be initialized until the first request that uses it.
-->

<!-- add property -->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>

<!-- SearchHandler
http://wiki.apache.org/solr/SearchHandler
For processing Search Queries, the primary Request Handler
provided with Solr is "SearchHandler" It delegates to a sequent
of SearchComponents (see below) and supports distributed
queries across multiple shards
-->
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
. 17
18 is
. 19
20 is
21 is
22 is
23 is
24
25
disposed below the document, is connected to support other databases mysql

query: query the database table for recording data meet
deltaQuery: increment primary key index query can return the ID Note ID field
deltaImportQuery: incremental indexing query data imported
> vim server / solr / new_core / conf / data-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataConfig>
<dataSource name="source"
type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/appstore"
user="root"
password="123456"
/>
<document>
<entity name="app"
pk="id"
dataSource="source"
query="select * from app"
deltaImportQuery="select * from app where id = '${dih.delta.id}'"
deltaQuery="select id from app where update_date > '${dataimporter.last_index_time}' and type = 1">
<field column="id" name="id"/>
<field column="update_date" name="update_date"/>
</entity>
</document>
</dataConfig>
1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
. 17
18 is
. 19
20 is
21 is
22 is
23 is
after that, you need to configure managed-schema file, map database, in the vicinity of 117 lines, add the mapping database, specifically Add a rule, I do not write in detail.

> vim server/solr/new_core/conf/managed-schema

<!-- add propertity -->
<field name="appName" type="string" indexed="true" stored="true" />
<field name="score" type="string" indexed="true" stored="true" />
<field name="downLoadNum" type="string" indexed="true" stored="true" />
<field name="top" type="string" indexed="true" stored="true" />
<field name="type" type="string" indexed="true" stored="true" />
<field name="update_date" type="string" indexed="true" stored="true" />restart solr. 9. 8. 7. 6. 5. 4. 32
. 1








> Solr restart -force
1
again increased core found to have increased success

 

 

 

Initialization data

 

Initialization is complete you can query the

 

If you modify the update operation can trigger

 

Of course, data can be updated by means of the requested URL, and also to facilitate updating procedures herein in combination index

http://172.16.3.148:8983/solr/new_core/dataimport?command=delta-import&clean=%20false&commit=true&wt=json&indent=true&verbose=false&optimize=false&debug=false
1
Solr search engine - two installation methods
to read the number 52

Often encounter a large list query demand in business development or search for content in accordance with the conditions of general practice are often database directly to get, but only to a certain extent this kind of demand will bring a huge overhead, a table data related to the five tables, from which the search request ... three tables
Bowen
from: meow had a microphone blog


csdnhsh: Some complex right (1 week ago # 8 floor)

5201314jie: > vim server/solr/new_core/conf/solrconfig.xml &lt;!-- Request Handlers http://wiki.apache.org/solr/SolrRequestHandler Incoming queries will be dispatched to a specific handler by name based on the path specified in the request. If a Request Handler is declared with startup="lazy", then it will not be initialized until the first request that uses it. --&gt; &lt;!-- add property --&gt; <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> &lt;!-- SearchHandler http://wiki.apache.org/solr/SearchHandler For processing Search Queries, the primary Request Handler provided with Solr is "SearchHandler" It delegates to a sequent of SearchComponents (see below) and supports distributed queries across multiple shards --&gt;(1周前#7楼)

5201314jie: > vim server/solr/new_core/conf/solrconfig.xml &lt;!-- Request Handlers http://wiki.apache.org/solr/SolrRequestHandler Incoming queries will be dispatched to a specific handler by name based on the path specified in the request. If a Request Handler is declared with startup="lazy", then it will not be initialized until the first request that uses it. --&gt; &lt;!-- add property --&gt; <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> &lt;!-- SearchHandler http://wiki.apache.org/solr/SearchHandler For processing Search Queries, the primary Request Handler provided with Solr is "SearchHandler" It delegates to a sequent of SearchComponents (see below) and supports distributed queries across multiple shards --&gt;
--------------------- 

Guess you like

Origin www.cnblogs.com/hyhy904/p/10992431.html