新建config配置类 继承LDConfig 实现 basicsConfig
public class DemoConfig extends LDConfig{ /** * 以下是基础配置 开启动态词库 优先使用本地词库 */ @Override public void basicsConfig() { Config config = new Config(); config.setLucene_path("d:/LuceneHome/core/"); config.setQueryNum(Integer.MAX_VALUE); config.setHighlight(true); LuceneDataSource dataSource = new LuceneDataSource(); dataSource.addDataSource(new Init(config, "test",new IKAnalyzer(false)).start()); LuceneDataSource.DynamicDictionary=true; LuceneDataSource.redis_host = "xx.xx.xx.xx"; } }
打开web.xml配置过滤器
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <filter> <filter-name>lucenePlus</filter-name> <filter-class>com.ld.zxw.core.CoreFilter</filter-class> <init-param> <param-name>configClass</param-name> <param-value>test.DemoConfig</param-value> </init-param> </filter> <filter-mapping> <filter-name>lucenePlus</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
在需要用的业务层定义 LuceneService 好了可以好好玩耍了
项目:LucenePlus