SOLR itself provides a tool library to implement timed incremental indexing, but I found some problems in the use of the process, and currently encountering two points:
1. The following exception is always reported on startup:
?
1 |
The web application [solr] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. |
Try to modify the source code, do not load the configuration file through Solrresourceloader, modify the deployment after completion, you can start normally.
2. After normal startup, the following exceptions are reported when the task is initiated regularly:
?
1 |
415 Unsupported Media Type |
View the Basetimertask class and find that there is no content-type added to the request header where the HTTP request was sent. The problem is resolved after the modification.
The code is specifically modified as follows, and the full source will be provided at the end:
Applicationlistener class:
?
12345678910 |
@Override
public
void
contextInitialized(ServletContextEvent servletContextEvent) {
...
Timer timer =
new
Timer();
HttpPostScheduler task =
new
HttpPostScheduler(
servletContext.getServletContextName(),
servletContext.getInitParameter(
"autoDeltaImportConfPath"
),
timer);
...
}
|
Solrdataimportproperties class:
?
12345678910111213141516171819 |
...
private
String autoDeltaImportConfPath;
public
SolrDataImportProperties() {
}
public SolrDataImportProperties(String autoDeltaImportConfPath) {
this
.autoDeltaImportConfPath = autoDeltaImportConfPath;
}
...
public
void
loadProperties(
boolean
force) {
try
{
if
(force || properties ==
null
) {
properties =
new
Properties();
File dataImportProperties =
new File(autoDeltaImportConfPath,
"dataimport.properties"
);
...
}
|
Httppostscheduler class:
?
123456789101112131415161718 |
public
HttpPostScheduler(String webAppName, String autoDeltaImportConfPath, Timer t)
throws
Exception{
...
//load properties from global dataimport.properties
p =
new
SolrDataImportProperties(autoDeltaImportConfPath);
...
}
...
private
void sendHttpPost(String completeUrl, String coreName){
...
URL url =
new
URL(completeUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod(
"POST"
);
conn.setRequestProperty(
"type"
,
"submit"
);
conn.setRequestProperty(
"Content-Type"
,
"*/*"
);
//新增
conn.setDoOutput(
true
);
...
}
|
Web. xml file:
?
1234567 |
<
context-param
>
<
param-name
>autoDeltaImportConfPath</
param-name
>
<
param-value
>/yourconfpath</
param-value
>
</
context-param
>
<
listener
>
<
listener-class
>org.apache.solr.handler.dataimport.scheduler.ApplicationListener</
listener-class
>
</
listener
>
|
It is also stated that the dataimport.properties can be placed at will, just specify the location above.
The source is hosted in Git OSC, the address is Http://git.oschina.net/ywooer/solr-dataimporthandler-scheduler.git
Reference Documentation:
Official document, Http://wiki.apache.org/solr/DataImportHandler#Scheduling
Official Tool Library: http://code.google.com/p/solr-data-import-scheduler/
There is also a third-party implementation Support Rebuild index: https://code.google.com/p/solr-dataimport-scheduler/
SOLR's timing incremental indexing implementation