开发者

update SQL command inside db-data-config.xml (solr)

Is it possible to put an update SQL command inside db-data-config.xml used for indexing in solr?

I need to save the last successful solr indexing date stamp in a database column. If I can include an update SQL command as part of the solr db-data-config.xml file I could accomplish this.

Is the开发者_如何学Cre an alternative to this requirement?


You cannot do it directly in the db-data-config.xml. What you can do is to use the EventListener. To do this you have to write a class that inherits the EventListner-interface and execute your update command on: 'onEvent'. In the event you will have access to the context params so you could make it generic and read your command from the configuration file.

To do this create a EventListner:

package se;

import org.apache.solr.handler.dataimport.Context;
import org.apache.solr.handler.dataimport.EventListener;


public class DataImportEndEventListner implements EventListener {

    /* (non-Javadoc)
     * @see org.apache.solr.handler.dataimport.EventListener#onEvent(org.apache.solr.handler.dataimport.Context)
     */
    @Override
    public void onEvent(Context ctx) {
        //read config
        ctx.getRequestParameters().get("parameter-name").toString());

        try
        {
            // Do what you want
        }
        catch(Exception ex)
        {
            // handle error
        }
    }

}

and register it in the db-data-config.xml:

<dataConfig>
<document onImportEnd="se.DataImportEndEventListner">
....
</document>
</dataConfig>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜