Commit 9c96653b by 石头

整合词条页面

1 parent 5cd291e3
...@@ -81,6 +81,8 @@ public class WordDomain implements Serializable { ...@@ -81,6 +81,8 @@ public class WordDomain implements Serializable {
private String wordSpell; private String wordSpell;
private String category; private String category;
private String wordAlias;
} }
...@@ -6,6 +6,8 @@ import tk.mybatis.mapper.entity.Example; ...@@ -6,6 +6,8 @@ import tk.mybatis.mapper.entity.Example;
import com.dookay.coral.common.core.persistence.criteria.QueryCriteria; import com.dookay.coral.common.core.persistence.criteria.QueryCriteria;
import com.dookay.cihai.core.word.domain.WordDomain; import com.dookay.cihai.core.word.domain.WordDomain;
import java.util.List;
/** /**
* 词条 * 词条
* *
...@@ -18,13 +20,27 @@ public class WordQuery extends Query { ...@@ -18,13 +20,27 @@ public class WordQuery extends Query {
private String keyword; private String keyword;
private List<String> keywordList;
@Override @Override
public QueryCriteria toCriteria() { public QueryCriteria toCriteria() {
QueryCriteria queryCriteria = new QueryCriteria(WordDomain.class); QueryCriteria queryCriteria = new QueryCriteria(WordDomain.class);
Example.Criteria criteria = queryCriteria.createCriteria(); Example.Criteria criteria = queryCriteria.createCriteria();
if (valid(keyword)) { if (valid(keyword)) {
String str = "%" + keyword + "%"; String str = "%" + keyword + "%";
criteria.andCondition(String.format("(word like '%s' or CONTAINS(%s,word))", str, keyword)); criteria.andCondition(String.format("(word like '%s' or word_alias like '%s')", str, str));
}
if (valid(keywordList)) {
String sql = "";
for (int i = 0; i < keywordList.size(); i++) {
if (i == 0) {
sql += " word like '%" + keywordList.get(i) + "%'";
} else {
sql += " or word like '%" + keywordList.get(i) + "%'";
}
}
System.out.println(sql);
criteria.andCondition(sql);
} }
//todo 写查询逻辑 //todo 写查询逻辑
return queryCriteria; return queryCriteria;
......
...@@ -17,6 +17,7 @@ package com.dookay.cihai.wechat.controller; ...@@ -17,6 +17,7 @@ package com.dookay.cihai.wechat.controller;
import com.dookay.cihai.core.aip.AipImageClassifyClient; import com.dookay.cihai.core.aip.AipImageClassifyClient;
import com.dookay.cihai.core.aip.AipWordUtilBean; import com.dookay.cihai.core.aip.AipWordUtilBean;
import com.dookay.cihai.core.aip.model.ImageResult; import com.dookay.cihai.core.aip.model.ImageResult;
import com.dookay.cihai.core.aip.model.LexerItem;
import com.dookay.cihai.core.theme.domain.ThemeDomain; import com.dookay.cihai.core.theme.domain.ThemeDomain;
import com.dookay.cihai.core.theme.query.ThemeQuery; import com.dookay.cihai.core.theme.query.ThemeQuery;
import com.dookay.cihai.core.theme.service.IThemeService; import com.dookay.cihai.core.theme.service.IThemeService;
...@@ -29,6 +30,7 @@ import com.dookay.cihai.core.word.service.IWordService; ...@@ -29,6 +30,7 @@ import com.dookay.cihai.core.word.service.IWordService;
import com.dookay.coral.common.web.constant.MediaTypes; import com.dookay.coral.common.web.constant.MediaTypes;
import com.dookay.coral.common.web.controller.BaseController; import com.dookay.coral.common.web.controller.BaseController;
import com.dookay.coral.common.web.response.JsonResult; import com.dookay.coral.common.web.response.JsonResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -37,6 +39,7 @@ import org.springframework.web.bind.annotation.ResponseBody; ...@@ -37,6 +39,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author 石磊 * @author 石磊
...@@ -79,7 +82,10 @@ public class HomeController extends BaseController { ...@@ -79,7 +82,10 @@ public class HomeController extends BaseController {
@RequestMapping(value = "/home/search", method = RequestMethod.GET) @RequestMapping(value = "/home/search", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public JsonResult search(String keyword) { public JsonResult search(String keyword) {
System.out.println("进入搜索"); System.out.println("进入搜索:" + keyword);
if (StringUtils.isBlank(keyword)) {
return errorResult("搜索内容不能为空");
}
String result = null; String result = null;
boolean inDic = false; boolean inDic = false;
List<CustomDictionaryDomain> dictionaryDomainList = customDictionaryService.getList(new CustomDictionaryQuery()); List<CustomDictionaryDomain> dictionaryDomainList = customDictionaryService.getList(new CustomDictionaryQuery());
...@@ -96,7 +102,19 @@ public class HomeController extends BaseController { ...@@ -96,7 +102,19 @@ public class HomeController extends BaseController {
ThemeQuery query = new ThemeQuery(); ThemeQuery query = new ThemeQuery();
query.setKeyword(result); query.setKeyword(result);
ThemeDomain themeDomain = themeService.getFirst(query); ThemeDomain themeDomain = themeService.getFirst(query);
if (themeDomain == null) return errorResult(String.format("暂无\"%s\"检索结果", keyword)); if (themeDomain == null) {
WordQuery wordQuery = new WordQuery();
wordQuery.setKeyword(result);
WordDomain wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) {
List<LexerItem> items = aipWordUtilBean.getLexerItems(result);
wordQuery.setKeywordList(items.stream().map(n -> n.getItem()).collect(Collectors.toList()));
wordQuery.setKeyword(null);
wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult(String.format("暂无\"%s\"检索结果", keyword));
}
return successResult("success", "/word/baike/" + wordDomain.getId());
}
System.out.println(themeDomain); System.out.println(themeDomain);
return successResult("success", "/theme/detail/" + themeDomain.getId()); return successResult("success", "/theme/detail/" + themeDomain.getId());
} catch (Exception ex) { } catch (Exception ex) {
...@@ -115,14 +133,18 @@ public class HomeController extends BaseController { ...@@ -115,14 +133,18 @@ public class HomeController extends BaseController {
System.out.println("进入图片检索"); System.out.println("进入图片检索");
try { try {
ImageResult imageResult = aipImageClassifyClient.getImageResult(image); ImageResult imageResult = aipImageClassifyClient.getImageResult(image);
System.out.println(imageResult);
String name = imageResult.getName(); String name = imageResult.getName();
System.out.println(name); System.out.println(name);
WordQuery wordQuery = new WordQuery(); WordQuery wordQuery = new WordQuery();
wordQuery.setKeyword(name); wordQuery.setKeyword(name);
WordDomain wordDomain = wordService.getFirst(wordQuery); WordDomain wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult("暂无检索结果"); if (wordDomain == null) {
List<LexerItem> items = aipWordUtilBean.getLexerItems(name);
wordQuery.setKeywordList(items.stream().map(n -> n.getItem()).collect(Collectors.toList()));
wordQuery.setKeyword(null);
wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult("暂无检索结果");
}
return successResult("success", "/word/baike/" + wordDomain.getId()); return successResult("success", "/word/baike/" + wordDomain.getId());
} catch (Exception ex) { } catch (Exception ex) {
return errorResult("暂无检索结果"); return errorResult("暂无检索结果");
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
wx.stopRecord({ wx.stopRecord({
success: function (res) { success: function (res) {
myApp.dialog.preloader(); myApp.dialog.preloader();
var localId = res.localId; var localId = res.localId;
wx.translateVoice({ wx.translateVoice({
localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得 localId: localId, // 需要识别的音频的本地Id,由录音相关接口获得
......
...@@ -290,7 +290,7 @@ ...@@ -290,7 +290,7 @@
<div class="navbar"> <div class="navbar">
<div class="navbar-inner"> <div class="navbar-inner">
<div class="left"> <div class="left">
<a class="link back" href="/"> <a class="link back js-jump-page" href="/">
<i class="iconfont icon-jiantou"></i> <i class="iconfont icon-jiantou"></i>
<span class="ios-only">返回</span> <span class="ios-only">返回</span>
</a> </a>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!