Commit 9c96653b by 石头

整合词条页面

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