move config files stay with plugin
This commit is contained in:
parent
5b95ceb25a
commit
f9977456ee
4
pom.xml
4
pom.xml
@ -6,10 +6,10 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-analysis-ik</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<version>1.7.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<description>IK Analyzer for ElasticSearch</description>
|
||||
<inceptionYear>2009</inceptionYear>
|
||||
<inceptionYear>2011</inceptionYear>
|
||||
|
||||
<properties>
|
||||
<elasticsearch.version>2.1.1</elasticsearch.version>
|
||||
|
@ -1,10 +1,16 @@
|
||||
<?xml version="1.0"?>
|
||||
<assembly>
|
||||
<id></id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/config</directory>
|
||||
<outputDirectory>/config</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
|
||||
<files>
|
||||
<file>
|
||||
<source>${project.basedir}/src/main/resources/plugin-descriptor.properties</source>
|
||||
|
@ -23,11 +23,6 @@ import static java.rmi.Naming.bind;
|
||||
|
||||
|
||||
public class AnalysisIkPlugin extends Plugin {
|
||||
private final Settings settings;
|
||||
@Inject
|
||||
public AnalysisIkPlugin(Settings settings){
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override public String name() {
|
||||
return "analysis-ik";
|
||||
@ -43,7 +38,4 @@ public class AnalysisIkPlugin extends Plugin {
|
||||
return Collections.<Module>singletonList(new IKIndicesAnalysisModule());
|
||||
}
|
||||
|
||||
// public void onModule(AnalysisModule module) {
|
||||
// module.addProcessor(new IkAnalysisBinderProcessor());
|
||||
// }
|
||||
}
|
||||
|
@ -4,11 +4,15 @@
|
||||
package org.wltea.analyzer.cfg;
|
||||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.plugin.analysis.ik.AnalysisIkPlugin;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.InvalidPropertiesFormatException;
|
||||
import java.util.List;
|
||||
@ -31,12 +35,12 @@ public class Configuration {
|
||||
environment = env;
|
||||
|
||||
|
||||
File fileConfig= new File(environment.configFile().toFile(), FILE_NAME);
|
||||
Path fileConfig = PathUtils.get(getDictRoot(), FILE_NAME);
|
||||
|
||||
|
||||
InputStream input = null;
|
||||
try {
|
||||
input = new FileInputStream(fileConfig);
|
||||
input = new FileInputStream(fileConfig.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
@ -60,7 +64,7 @@ public class Configuration {
|
||||
if(filePaths != null){
|
||||
for(String filePath : filePaths){
|
||||
if(filePath != null && !"".equals(filePath.trim())){
|
||||
File file=new File("ik",filePath.trim());
|
||||
Path file = PathUtils.get("ik", filePath.trim());
|
||||
extDictFiles.add(file.toString());
|
||||
|
||||
}
|
||||
@ -97,7 +101,7 @@ public class Configuration {
|
||||
if(filePaths != null){
|
||||
for(String filePath : filePaths){
|
||||
if(filePath != null && !"".equals(filePath.trim())){
|
||||
File file=new File("ik",filePath.trim());
|
||||
Path file = PathUtils.get("ik", filePath.trim());
|
||||
extStopWordDictFiles.add(file.toString());
|
||||
|
||||
}
|
||||
@ -121,11 +125,13 @@ public class Configuration {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return remoteExtStopWordDictFiles;
|
||||
}
|
||||
|
||||
public File getDictRoot() {
|
||||
return environment.configFile().toFile();
|
||||
public String getDictRoot() {
|
||||
return PathUtils.get(
|
||||
new File(AnalysisIkPlugin.class.getProtectionDomain().getCodeSource().getLocation().getPath()).getParent(),"config")
|
||||
.toAbsolutePath().toString();
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -45,6 +46,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.elasticsearch.common.io.PathUtils;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.wltea.analyzer.cfg.Configuration;
|
||||
@ -220,11 +222,11 @@ public class Dictionary {
|
||||
_MainDict = new DictSegment((char)0);
|
||||
|
||||
//读取主词典文件
|
||||
File file= new File(configuration.getDictRoot(), Dictionary.PATH_DIC_MAIN);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), Dictionary.PATH_DIC_MAIN);
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -269,9 +271,9 @@ public class Dictionary {
|
||||
for(String extDictName : extDictFiles){
|
||||
//读取扩展词典文件
|
||||
logger.info("[Dict Loading]" + extDictName);
|
||||
File file=new File(configuration.getDictRoot(), extDictName);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), extDictName);
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
@ -385,11 +387,11 @@ public class Dictionary {
|
||||
_StopWords = new DictSegment((char)0);
|
||||
|
||||
//读取主词典文件
|
||||
File file= new File(configuration.getDictRoot(), Dictionary.PATH_DIC_STOP);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), Dictionary.PATH_DIC_STOP);
|
||||
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -427,9 +429,9 @@ public class Dictionary {
|
||||
logger.info("[Dict Loading]" + extStopWordDictName);
|
||||
|
||||
//读取扩展词典文件
|
||||
file=new File(configuration.getDictRoot(), extStopWordDictName);
|
||||
file=PathUtils.get(configuration.getDictRoot(), extStopWordDictName);
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
@ -493,10 +495,10 @@ public class Dictionary {
|
||||
//建立一个量词典实例
|
||||
_QuantifierDict = new DictSegment((char)0);
|
||||
//读取量词词典文件
|
||||
File file=new File(configuration.getDictRoot(),Dictionary.PATH_DIC_QUANTIFIER);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), Dictionary.PATH_DIC_QUANTIFIER);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
@ -529,10 +531,10 @@ public class Dictionary {
|
||||
private void loadSurnameDict(){
|
||||
|
||||
_SurnameDict = new DictSegment((char)0);
|
||||
File file=new File(configuration.getDictRoot(),Dictionary.PATH_DIC_SURNAME);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), Dictionary.PATH_DIC_SURNAME);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
@ -566,10 +568,10 @@ public class Dictionary {
|
||||
private void loadSuffixDict(){
|
||||
|
||||
_SuffixDict = new DictSegment((char)0);
|
||||
File file=new File(configuration.getDictRoot(),Dictionary.PATH_DIC_SUFFIX);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), Dictionary.PATH_DIC_SUFFIX);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
@ -602,10 +604,10 @@ public class Dictionary {
|
||||
private void loadPrepDict(){
|
||||
|
||||
_PrepDict = new DictSegment((char)0);
|
||||
File file=new File(configuration.getDictRoot(),Dictionary.PATH_DIC_PREP);
|
||||
Path file = PathUtils.get(configuration.getDictRoot(), Dictionary.PATH_DIC_PREP);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(file);
|
||||
is = new FileInputStream(file.toFile());
|
||||
} catch (FileNotFoundException e) {
|
||||
logger.error("ik-analyzer",e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user