简体   繁体   中英

How to debug Solr plugin?

I have written a search component to be used with SOLR. I want to debug it. I tried debugging the SOLR itself using remote debugging feature of eclipse but it doesn't work for plugin and shows source not found.

Then I tried including my plugin project as source project but that did not work either. The debugger doesn't stops at breakpoints for plugin.

Any help in this regard shall be greatly appreciated!

You can write a Junit test in your eclipse project using an embedded solr. This makes debugging easier. All you need to do, is to create the config files for the solr-core (solrconfig.xml, schema.xml, etc.; you could probably copy the solr core dir from your solr installation) in your test resources directory and point the CoreContainer to that directory. This core container can be used to get the configured solr core and your searcher. JUnit and Solr-core are the dependencies needed.

Below is an example of the test-code:

/**
 * This is a starting point for testing the component with embedded solr!
 */
public class SearchComponentTest
{
    private static CoreContainer container;
    private static SolrCore core;

    private static final Logger logger = LoggerFactory.getLogger(DataImportRequestHandlerTest.class.getName());

    /*
     * PREPARE AND TEAR DOWN FOR TESTS
     */
    @BeforeClass
    public static void prepareClass() throws Exception
    {
        // create the coreContainer from conf dir in test resources
        container = new CoreContainer(
            DataImportRequestHandlerTest.class.getResource("/solrDir").getPath().substring(1));
        container.load();
        core = container.getCore("CORENAME");
        logger.info("Solr core loaded!");
    }

    @AfterClass
    public static void cleanUpClass()
    {
        core.close();
        container.shutdown();
        logger.info("Solr core shut down!");
    }

    /* TESTS TO RUN */

    /**
     * Test the search component here or just trigger it to debug
     */
    @Test
    public void testSearchComponent()
    {
        /* PREPARE */
        SearchComponent mySearchComp = core.getSearchComponent("componentNameFromSolrConf");

        /* RUN */
        // do something with your search component

        /* CHECK */
        // check results with asserts :)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM