Shinsuke Sugaya 10 年之前
父節點
當前提交
933c31a1f5

+ 1 - 0
.gitignore

@@ -18,3 +18,4 @@
 *.iml
 *.iml
 .idea
 .idea
 .DS_Store
 .DS_Store
+/plugins/

+ 29 - 0
pom.xml

@@ -49,6 +49,8 @@
     <tomcat.useSeparateTomcatClassLoader>true</tomcat.useSeparateTomcatClassLoader>
     <tomcat.useSeparateTomcatClassLoader>true</tomcat.useSeparateTomcatClassLoader>
     <maven.tomcat.uriEncoding>UTF-8</maven.tomcat.uriEncoding>
     <maven.tomcat.uriEncoding>UTF-8</maven.tomcat.uriEncoding>
     <maven.tomcat.tomcatUsers.file>${basedir}/src/test/resources/tomcat-users.xml</maven.tomcat.tomcatUsers.file>
     <maven.tomcat.tomcatUsers.file>${basedir}/src/test/resources/tomcat-users.xml</maven.tomcat.tomcatUsers.file>
+    <maven.snapshot.repo.url>https://oss.sonatype.org/content/repositories/snapshots</maven.snapshot.repo.url>
+    <maven.release.repo.url>http://central.maven.org/maven2</maven.release.repo.url>
   </properties>
   </properties>
   <build>
   <build>
     <finalName>fess</finalName>
     <finalName>fess</finalName>
@@ -185,6 +187,33 @@
           <dbfluteClientDir>${basedir}/dbflute_fess</dbfluteClientDir>
           <dbfluteClientDir>${basedir}/dbflute_fess</dbfluteClientDir>
         </configuration>
         </configuration>
       </plugin>
       </plugin>
+      <plugin>
+        <artifactId>maven-antrun-plugin</artifactId>
+        <version>1.8</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.apache.ant</groupId>
+            <artifactId>ant</artifactId>
+            <version>1.9.6</version>
+          </dependency>
+        </dependencies>
+        <configuration>
+          <tasks>
+            <mkdir dir="${basedir}/target/plugins"/>
+            <get dest="${basedir}/target/plugins">
+              <url url="${maven.snapshot.repo.url}/org/codelibs/elasticsearch-configsync/1.6.0-SNAPSHOT/elasticsearch-configsync-1.6.0-20150716.075532-2.zip"/>
+              <url url="${maven.release.repo.url}/org/codelibs/elasticsearch-analysis-kuromoji-neologd/1.6.0/elasticsearch-analysis-kuromoji-neologd-1.6.0.zip"/>
+            </get>
+            <delete dir="${basedir}/plugins"/>
+            <mkdir dir="${basedir}/plugins"/>
+            <unzip dest="${basedir}/plugins/analysis-kuromoji-neologd" src="${basedir}/target/plugins/elasticsearch-analysis-kuromoji-neologd-1.6.0.zip"/>
+            <unzip dest="${basedir}/plugins/configsync" src="${basedir}/target/plugins/elasticsearch-configsync-1.6.0-20150716.075532-2.zip"/>
+          </tasks>
+        </configuration>
+        <goals>
+          <goal>run</goal>
+        </goals>
+      </plugin>
     </plugins>
     </plugins>
   </build>
   </build>
   <pluginRepositories>
   <pluginRepositories>

+ 38 - 0
src/main/java/org/codelibs/fess/client/FessEsClient.java

@@ -2,7 +2,10 @@ package org.codelibs.fess.client;
 
 
 import static org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;
 import static org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;
 
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Map.Entry;
@@ -15,6 +18,8 @@ import org.codelibs.core.io.FileUtil;
 import org.codelibs.core.lang.StringUtil;
 import org.codelibs.core.lang.StringUtil;
 import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner;
 import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner;
 import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.Configs;
 import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.Configs;
+import org.codelibs.elasticsearch.runner.net.Curl;
+import org.codelibs.elasticsearch.runner.net.CurlResponse;
 import org.codelibs.fess.Constants;
 import org.codelibs.fess.Constants;
 import org.codelibs.fess.ResultOffsetExceededException;
 import org.codelibs.fess.ResultOffsetExceededException;
 import org.codelibs.fess.entity.FacetInfo;
 import org.codelibs.fess.entity.FacetInfo;
@@ -159,10 +164,21 @@ public class FessEsClient implements Client {
 
 
     protected List<String> indexConfigList = new ArrayList<>();
     protected List<String> indexConfigList = new ArrayList<>();
 
 
+    protected Map<String, List<String>> configListMap = new HashMap<>();
+
     public void addIndexConfig(String path) {
     public void addIndexConfig(String path) {
         indexConfigList.add(path);
         indexConfigList.add(path);
     }
     }
 
 
+    public void addConfigFile(String index, String path) {
+        List<String> list = configListMap.get(index);
+        if (list == null) {
+            list = new ArrayList<>();
+            configListMap.put(index, list);
+        }
+        list.add(path);
+    }
+
     public void setSettings(Map<String, String> settings) {
     public void setSettings(Map<String, String> settings) {
         this.settings = settings;
         this.settings = settings;
     }
     }
@@ -214,6 +230,7 @@ public class FessEsClient implements Client {
                     if (settings != null) {
                     if (settings != null) {
                         settingsBuilder.put(settings);
                         settingsBuilder.put(settings);
                     }
                     }
+                    settingsBuilder.put("path.plugins", System.getProperty("user.dir") + "/plugins");
                 });
                 });
                 runner.build(config);
                 runner.build(config);
             }
             }
@@ -263,6 +280,27 @@ public class FessEsClient implements Client {
                     // ignore
                     // ignore
             }
             }
             if (!exists) {
             if (!exists) {
+                if (runner != null) {// TODO replace with url
+                    configListMap.getOrDefault(configIndex, Collections.emptyList()).forEach(
+                            path -> {
+                                String source = null;
+                                final String filePath = indexConfigPath + "/" + configIndex + "/" + path;
+                                try {
+                                    source = FileUtil.readUTF8(filePath);
+                                    try (CurlResponse response =
+                                            Curl.post(runner.node(), "_configsync/file").param("path", path).body(source).execute()) {
+                                        if (response.getHttpStatusCode() == 200) {
+                                            logger.info("Register " + path + " to " + configIndex);
+                                        } else {
+                                            logger.warn("Invalid request for " + path);
+                                        }
+                                    }
+                                } catch (final Exception e) {
+                                    logger.warn("Failed to register " + filePath, e);
+                                }
+                            });
+                }
+
                 try {
                 try {
                     String source = null;
                     String source = null;
                     final String indexConfigFile = indexConfigPath + "/" + configIndex + ".json";
                     final String indexConfigFile = indexConfigPath + "/" + configIndex + ".json";

+ 12 - 0
src/main/resources/esclient.dicon

@@ -9,6 +9,18 @@
 		<initMethod name="addIndexConfig">
 		<initMethod name="addIndexConfig">
 			<arg>"fess/doc"</arg>
 			<arg>"fess/doc"</arg>
 		</initMethod>
 		</initMethod>
+		<initMethod name="addConfigFile">
+			<arg>"fess"</arg>
+			<arg>"ja/mapping.txt"</arg>
+		</initMethod>
+		<initMethod name="addConfigFile">
+			<arg>"fess"</arg>
+			<arg>"ja/synonym.txt"</arg>
+		</initMethod>
+		<initMethod name="addConfigFile">
+			<arg>"fess"</arg>
+			<arg>"ja/kuromoji.txt"</arg>
+		</initMethod>
 		<initMethod name="addIndexConfig">
 		<initMethod name="addIndexConfig">
 			<arg>".fess_config/boost_document_rule"</arg>
 			<arg>".fess_config/boost_document_rule"</arg>
 		</initMethod>
 		</initMethod>

+ 3 - 0
src/main/resources/fess_indices/fess/ja/kuromoji.txt

@@ -0,0 +1,3 @@
+日本経済新聞,日本 経済 新聞,ニホン ケイザイ シンブン,カスタム名詞
+関西国際空港,関西 国際 空港,カンサイ コクサイ クウコウ,テスト名詞
+朝青龍,朝青龍,アサショウリュウ,カスタム名詞

+ 189 - 0
src/main/resources/fess_indices/fess/ja/mapping.txt

@@ -0,0 +1,189 @@
+# Half-width Katakana => Full-width Katakana
+"ア" => "ア"
+"イ" => "イ"
+"ウ" => "ウ"
+"エ" => "エ"
+"オ" => "オ"
+"カ" => "カ"
+"キ" => "キ"
+"ク" => "ク"
+"ケ" => "ケ"
+"コ" => "コ"
+"サ" => "サ"
+"シ" => "シ"
+"ス" => "ス"
+"セ" => "セ"
+"ソ" => "ソ"
+"タ" => "タ"
+"チ" => "チ"
+"ツ" => "ツ"
+"テ" => "テ"
+"ト" => "ト"
+"ナ" => "ナ"
+"ニ" => "ニ"
+"ヌ" => "ヌ"
+"ネ" => "ネ"
+"ノ" => "ノ"
+"ハ" => "ハ"
+"ヒ" => "ヒ"
+"フ" => "フ"
+"ヘ" => "ヘ"
+"ホ" => "ホ"
+"マ" => "マ"
+"ミ" => "ミ"
+"ム" => "ム"
+"メ" => "メ"
+"モ" => "モ"
+"ヤ" => "ヤ"
+"ユ" => "ユ"
+"ヨ" => "ヨ"
+"ラ" => "ラ"
+"リ" => "リ"
+"ル" => "ル"
+"レ" => "レ"
+"ロ" => "ロ"
+"ワ" => "ワ"
+"ヲ" => "ヲ"
+"ン" => "ン"
+"ッ" => "ッ"
+"ァ" => "ァ"
+"ィ" => "ィ"
+"ゥ" => "ゥ"
+"ェ" => "ェ"
+"ォ" => "ォ"
+"ャ" => "ャ"
+"ュ" => "ュ"
+"ョ" => "ョ"
+"ガ" => "ガ"
+"ギ" => "ギ"
+"グ" => "グ"
+"ゲ" => "ゲ"
+"ゴ" => "ゴ"
+"ザ" => "ザ"
+"ジ" => "ジ"
+"ズ" => "ズ"
+"ゼ" => "ゼ"
+"ゾ" => "ゾ"
+"ダ" => "ダ"
+"ヂ" => "ヂ"
+"ヅ" => "ヅ"
+"デ" => "デ"
+"ド" => "ド"
+"バ" => "バ"
+"ビ" => "ビ"
+"ブ" => "ブ"
+"ベ" => "ベ"
+"ボ" => "ボ"
+"パ" => "パ"
+"ピ" => "ピ"
+"プ" => "プ"
+"ペ" => "ペ"
+"ポ" => "ポ"
+
+# Full-width alpha-numeric => Half-width alpha-numeric
+"0" => "0"
+"1" => "1"
+"2" => "2"
+"3" => "3"
+"4" => "4"
+"5" => "5"
+"6" => "6"
+"7" => "7"
+"8" => "8"
+"9" => "9"
+
+"A" => "A"
+"B" => "B"
+"C" => "C"
+"D" => "D"
+"E" => "E"
+"F" => "F"
+"G" => "G"
+"H" => "H"
+"I" => "I"
+"J" => "J"
+"K" => "K"
+"L" => "L"
+"M" => "M"
+"N" => "N"
+"O" => "O"
+"P" => "P"
+"Q" => "Q"
+"R" => "R"
+"S" => "S"
+"T" => "T"
+"U" => "U"
+"V" => "V"
+"W" => "W"
+"X" => "X"
+"Y" => "Y"
+"Z" => "Z"
+
+"a" => "a"
+"b" => "b"
+"c" => "c"
+"d" => "d"
+"e" => "e"
+"f" => "f"
+"g" => "g"
+"h" => "h"
+"i" => "i"
+"j" => "j"
+"k" => "k"
+"l" => "l"
+"m" => "m"
+"n" => "n"
+"o" => "o"
+"p" => "p"
+"q" => "q"
+"r" => "r"
+"s" => "s"
+"t" => "t"
+"u" => "u"
+"v" => "v"
+"w" => "w"
+"x" => "x"
+"y" => "y"
+"z" => "z"
+
+# !"#$%&'()=|-^\@[`{;:]+*}/_<>?
+"!" => "!"
+"”" => "\""
+"#" => "#"
+"$" => "$"
+"%" => "%"
+"&" => "&"
+"’" => "'"
+"(" => "("
+")" => ")"
+"=" => "="
+"|" => "|"
+"-" => "-"
+"^" => "^"
+"¥" => "\\"
+"@" => "@"
+"[" => "["
+"`" => "`"
+"{" => "{"
+";" => ";"
+":" => ":"
+"]" => "]"
+"+" => "+"
+"*" => "*"
+"}" => "}"
+"/" => "/"
+"_" => "_"
+"<" => "<"
+">" => ">"
+"?" => "?"
+"‘" => "`"
+
+"①" => "1"
+"②" => "2"
+"③" => "3"
+"④" => "4"
+"⑤" => "5"
+"⑥" => "6"
+"⑦" => "7"
+"⑧" => "8"
+"⑨" => "9"

+ 1 - 0
src/main/resources/fess_indices/fess/ja/synonym.txt

@@ -0,0 +1 @@
+fess,フェス