繁体   English   中英

如何调试Solr插件?

[英]How to debug Solr plugin?

我已经编写了一个与SOLR一起使用的搜索组件。 我要调试它。 我尝试使用eclipse的远程调试功能调试SOLR本身,但不适用于插件,并显示未找到源。

然后,我尝试将插件项目作为源项目包括在内,但这也不起作用。 调试器不会在插件的断点处停止。

在这方面的任何帮助将不胜感激!

您可以使用嵌入式solr在Eclipse项目中编写Junit测试。 这使调试更加容易。 您需要做的就是在测试资源目录中为solr-core创建配置文件(solrconfig.xml,schema.xml等;您可能会从solr安装中复制solr核心目录)。该目录的CoreContainer 此核心容器可用于获取已配置的solr核心和您的搜索器。 JUnit和Solr-core是所需的依赖项。

以下是测试代码的示例:

/**
 * 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 :)
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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