SOLR's timing incremental indexing implementation

Source: Internet
Author: User
Tags solr

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 415Unsupported 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 @OverridepublicvoidcontextInitialized(ServletContextEvent servletContextEvent) {    ...    Timer timer = newTimer();    HttpPostScheduler task = newHttpPostScheduler(    servletContext.getServletContextName(),    servletContext.getInitParameter("autoDeltaImportConfPath"),         timer);    ...     }

Solrdataimportproperties class:

?
12345678910111213141516171819 ...privateString autoDeltaImportConfPath;publicSolrDataImportProperties() {}public SolrDataImportProperties(String autoDeltaImportConfPath) {    this.autoDeltaImportConfPath = autoDeltaImportConfPath;}...publicvoidloadProperties(booleanforce) {    try{        if(force || properties == null) {            properties = newProperties();            File dataImportProperties = new File(autoDeltaImportConfPath,                                "dataimport.properties");    ...}

Httppostscheduler class:

?
123456789101112131415161718 publicHttpPostScheduler(String webAppName, String autoDeltaImportConfPath, Timer t) throwsException{...    //load properties from global dataimport.properties    p = newSolrDataImportProperties(autoDeltaImportConfPath);...             }...privatevoid sendHttpPost(String completeUrl, String coreName){...        URL url = newURL(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.