|
|
package com.yoho.search.consumer.dynwords;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Controller
|
|
|
public class DynSegWordsToolsController {
|
|
|
|
...
|
...
|
@@ -32,6 +26,7 @@ public class DynSegWordsToolsController { |
|
|
private ESWordsService esWordsService;
|
|
|
|
|
|
private static Map<String, Integer> allDictFiles = new LinkedHashMap<String, Integer>();
|
|
|
|
|
|
static {
|
|
|
// 词的类型 1为主词典的词 2为停用词 3为姓氏 4为量词 5为后缀词 6为介词
|
|
|
allDictFiles.put("main.dic", Integer.valueOf(1)); // IK主词典
|
...
|
...
|
@@ -147,27 +142,23 @@ public class DynSegWordsToolsController { |
|
|
if (request.getParameter("words") != null && request.getParameter("words").trim().length() > 0) {
|
|
|
words = request.getParameter("words").trim();
|
|
|
}
|
|
|
Assert.isTrue(words != null && !words.trim().isEmpty(), "Words cannot be null.");
|
|
|
|
|
|
String wordType = "1";
|
|
|
if (request.getParameter("wordType") != null && request.getParameter("wordType").trim().length() > 0) {
|
|
|
wordType = request.getParameter("wordType").trim();
|
|
|
}
|
|
|
|
|
|
if ("7".equals(wordType)) {
|
|
|
// 调用/dictTools/addNewSynonymRule添加同义词
|
|
|
rtnMap.put("code", "404");
|
|
|
rtnMap.put("msg", "invalid word type");
|
|
|
logger.info("[DynSegWords]DynSegWordsToolsController.addNewWords end. cost: {}",
|
|
|
System.currentTimeMillis() - begin);
|
|
|
return rtnMap;
|
|
|
}
|
|
|
|
|
|
Set<String> wordSet = new HashSet<String>();
|
|
|
if ("7".equals(wordType)) {
|
|
|
wordSet.add(words.trim());
|
|
|
} else {
|
|
|
for (String word : words.split(",")) {
|
|
|
if (word != null && word.trim().length() > 0) {
|
|
|
wordSet.add(word.trim());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Set<String> addedWords = esWordsService.addNewWords(wordSet, Integer.valueOf(wordType));
|
|
|
rtnMap.put("code", "200");
|
...
|
...
|
@@ -189,27 +180,23 @@ public class DynSegWordsToolsController { |
|
|
if (request.getParameter("words") != null && request.getParameter("words").trim().length() > 0) {
|
|
|
words = request.getParameter("words").trim();
|
|
|
}
|
|
|
Assert.isTrue(words != null && !words.trim().isEmpty(), "Words cannot be null.");
|
|
|
|
|
|
String wordType = "1";
|
|
|
if (request.getParameter("wordType") != null && request.getParameter("wordType").trim().length() > 0) {
|
|
|
wordType = request.getParameter("wordType").trim();
|
|
|
}
|
|
|
|
|
|
if ("7".equals(wordType)) {
|
|
|
// 调用/dictTools/addNewSynonymRule添加同义词
|
|
|
rtnMap.put("code", "404");
|
|
|
rtnMap.put("msg", "invalid word type");
|
|
|
logger.info("[DynSegWords]DynSegWordsToolsController.reactiveWords end. cost: {}",
|
|
|
System.currentTimeMillis() - begin);
|
|
|
return rtnMap;
|
|
|
}
|
|
|
|
|
|
Set<String> wordSet = new HashSet<String>();
|
|
|
if ("7".equals(wordType)) {
|
|
|
wordSet.add(words.trim());
|
|
|
} else {
|
|
|
for (String word : words.split(",")) {
|
|
|
if (word != null && word.trim().length() > 0) {
|
|
|
wordSet.add(word.trim());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
esWordsService.reactiveWords(wordSet, Integer.valueOf(wordType));
|
|
|
rtnMap.put("code", "200");
|
...
|
...
|
@@ -231,12 +218,23 @@ public class DynSegWordsToolsController { |
|
|
words = request.getParameter("words").trim();
|
|
|
}
|
|
|
|
|
|
Assert.isTrue(words != null && !words.trim().isEmpty(), "Words cannot be null.");
|
|
|
|
|
|
String wordType = "1";
|
|
|
if (request.getParameter("wordType") != null && request.getParameter("wordType").trim().length() > 0) {
|
|
|
wordType = request.getParameter("wordType").trim();
|
|
|
}
|
|
|
|
|
|
List<String> list = new ArrayList<String>();
|
|
|
if ("7".equals(wordType)) {
|
|
|
list.add(words.trim());
|
|
|
} else {
|
|
|
for (String word : words.split(",")) {
|
|
|
if (word != null && word.trim().length() > 0) {
|
|
|
list.add(word.trim());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
esWordsService.deleteWords(list);
|
|
|
rtnMap.put("code", "200");
|
...
|
...
|
|