REPORT-6453 alphafine整合小帆 * commit '6e95b0939a7e07de101db5b25715f3a9a9b2fe1a': 提升代码质量。。 解决冲突,并提升代码质量 解决冲突,并提升代码质量 规范国际化文件及国际化定义。 提升alphafine代码质量 提升alphafine代码质量 提升alphafine代码质量 规范国际化文件及国际化定义。 规范国际化文件及国际化定义。research/10.0
@ -0,0 +1,58 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
|
||||
import java.awt.Desktop; |
||||
import java.io.IOException; |
||||
import java.net.URI; |
||||
import java.net.URISyntaxException; |
||||
|
||||
/** |
||||
* Created by alexsung on 2018/7/30. |
||||
*/ |
||||
public class BottomModel extends AlphaCellModel { |
||||
/** |
||||
* 找不到答案?去论坛提问 |
||||
*/ |
||||
public String getGoToWeb() { |
||||
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Internet_Forum"); |
||||
} |
||||
|
||||
public BottomModel(String name, String content) { |
||||
super(name, content, CellType.BOTTOM); |
||||
} |
||||
|
||||
public BottomModel() { |
||||
super(null, null, CellType.BOTTOM); |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject modelToJson() throws JSONException { |
||||
return JSONObject.EMPTY; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return ""; |
||||
} |
||||
|
||||
@Override |
||||
public boolean hasAction() { |
||||
return true; |
||||
} |
||||
|
||||
@Override |
||||
public void doAction() { |
||||
try { |
||||
Desktop.getDesktop().browse(new URI(AlphaFineConstants.ALPHA_GO_TO_FORUM)); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} catch (URISyntaxException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.model; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
|
||||
import java.awt.Desktop; |
||||
import java.io.IOException; |
||||
import java.net.URI; |
||||
import java.net.URISyntaxException; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class RobotModel extends AlphaCellModel { |
||||
|
||||
private String title; |
||||
private String content; |
||||
|
||||
//热门问题列表的list不需要渲染图标,所以这里需要区分一下
|
||||
private boolean hotItemModel = false; |
||||
|
||||
public boolean isHotItemModel() { |
||||
return hotItemModel; |
||||
} |
||||
|
||||
public void setHotItemModel(boolean hotItemModel) { |
||||
this.hotItemModel = hotItemModel; |
||||
} |
||||
|
||||
public String getTitle() { |
||||
return title; |
||||
} |
||||
|
||||
public void setTitle(String title) { |
||||
this.title = title; |
||||
} |
||||
|
||||
public static String getContent(String titleStr) { |
||||
String result; |
||||
String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + titleStr); |
||||
String url = AlphaFineConstants.ALPHA_GO_TO_WEB + titleStr + "&token=" + token; |
||||
HttpClient httpClient = new HttpClient(url); |
||||
httpClient.asGet(); |
||||
result = httpClient.getResponseText(); |
||||
AlphaFineHelper.checkCancel(); |
||||
try { |
||||
JSONObject jsonObject = new JSONObject(result); |
||||
return jsonObject.optString("msg"); |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("get robotmodel content error: " + e.getMessage()); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public RobotModel(String title, String content) { |
||||
super(title, content, CellType.ROBOT); |
||||
this.title = title; |
||||
} |
||||
|
||||
@Override |
||||
public JSONObject modelToJson() throws JSONException { |
||||
JSONObject object = JSONObject.create(); |
||||
try { |
||||
JSONObject modelObject = JSONObject.create(); |
||||
modelObject.put("title", getTitle()).put("content", getContent()).put("searchCount", getSearchCount()); |
||||
object.put("result", modelObject).put("cellType", getType().getTypeValue()); |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("RobotModel: " + e.getMessage()); |
||||
} |
||||
return object; |
||||
} |
||||
|
||||
@Override |
||||
public String getStoreInformation() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void doAction() { |
||||
try { |
||||
Desktop.getDesktop().browse(new URI("http://robot.finereport.com?send=" + super.getName())); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} catch (URISyntaxException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@
|
||||
package com.fr.design.mainframe.alphafine.cell.render; |
||||
|
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.cell.model.BottomModel; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.Component; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Dimension; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class BottomCellRender implements ListCellRenderer<Object> { |
||||
@Override |
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||||
|
||||
UILabel goToWebLabel = new UILabel(); |
||||
BottomModel bottomModel = (BottomModel) value; |
||||
JPanel panel = new JPanel(new BorderLayout()); |
||||
panel.setBackground(null); |
||||
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); |
||||
|
||||
JPanel line = new JPanel(); |
||||
line.setPreferredSize(new Dimension(200, 1)); |
||||
line.setBackground(AlphaFineConstants.GRAY); |
||||
panel.add(line, BorderLayout.NORTH); |
||||
|
||||
goToWebLabel.setFont(AlphaFineConstants.MEDIUM_FONT); |
||||
goToWebLabel.setText(bottomModel.getGoToWeb()); |
||||
goToWebLabel.setForeground(AlphaFineConstants.BLUE); |
||||
goToWebLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); |
||||
panel.add(goToWebLabel, BorderLayout.EAST); |
||||
|
||||
panel.setPreferredSize(new Dimension(list.getFixedCellWidth(), AlphaFineConstants.CELL_TITLE_HEIGHT)); |
||||
return panel; |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
import com.bulenkov.iconloader.IconLoader; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
|
||||
import javax.swing.JPanel; |
||||
import java.awt.Color; |
||||
import java.awt.Graphics; |
||||
|
||||
/** |
||||
* @Author alex.sung |
||||
* created by 2018.08.15 |
||||
*/ |
||||
public class ContainsCirclePane extends JPanel { |
||||
|
||||
public ContainsCirclePane(int pngIndex) { |
||||
UILabel iconLabel = new UILabel(IconLoader.getIcon(AlphaFineConstants.IMAGE_URL + AlphaFineConstants.ALPHA_HOT_IMAGE_NAME + pngIndex + ".png")); |
||||
iconLabel.setPreferredSize(AlphaFineConstants.HOT_ICON_LABEL_SIZE); |
||||
iconLabel.setOpaque(true); |
||||
iconLabel.setBackground(Color.WHITE); |
||||
add(iconLabel); |
||||
} |
||||
|
||||
@Override |
||||
public void paintComponent(Graphics g) { |
||||
super.paintComponent(g); |
||||
int height = AlphaFineConstants.HOT_ICON_LABEL_HEIGHT; |
||||
setBackground(Color.white); |
||||
int x0 = getSize().width / 2; |
||||
int y0 = height / 2 + 23; |
||||
int r = height / 2 + 9; |
||||
g.setColor(AlphaFineConstants.LIGHT_GRAY); |
||||
g.drawOval(x0 - r, y0 - r, r * 2, r * 2); |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fr.design.mainframe.alphafine.preview; |
||||
|
||||
|
||||
import com.fr.design.gui.itextarea.UITextArea; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
|
||||
import javax.swing.BorderFactory; |
||||
import javax.swing.JEditorPane; |
||||
import javax.swing.JPanel; |
||||
import javax.swing.JScrollPane; |
||||
import javax.swing.text.html.HTMLEditorKit; |
||||
import java.awt.BorderLayout; |
||||
import java.awt.Color; |
||||
import java.awt.Dimension; |
||||
|
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class RobotPreviewPane extends JPanel { |
||||
|
||||
public RobotPreviewPane(String title, String content) { |
||||
this.setLayout(new BorderLayout()); |
||||
this.setBackground(Color.WHITE); |
||||
this.setPreferredSize(new Dimension(AlphaFineConstants.RIGHT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT)); |
||||
UITextArea titleArea = new UITextArea(title); |
||||
titleArea.setBorder(null); |
||||
titleArea.setEditable(false); |
||||
titleArea.setForeground(AlphaFineConstants.BLUE); |
||||
titleArea.setFont(AlphaFineConstants.LARGE_FONT); |
||||
add(titleArea, BorderLayout.NORTH); |
||||
|
||||
JEditorPane editorPane = new JEditorPane(); |
||||
editorPane.setEditorKit(new HTMLEditorKit()); |
||||
editorPane.setText(content); |
||||
editorPane.setEditable(false); |
||||
JScrollPane jScrollPane = new JScrollPane(editorPane); |
||||
jScrollPane.setBorder(BorderFactory.createMatteBorder(5, 10, 0, 10, Color.white)); |
||||
add(jScrollPane, BorderLayout.CENTER); |
||||
} |
||||
} |
@ -0,0 +1,83 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.model.RobotModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.JSONUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import java.io.IOException; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
|
||||
/** |
||||
* @author alex.sung created on 2018/7/23. |
||||
*/ |
||||
public class ComplementAdviceManager { |
||||
|
||||
private static volatile ComplementAdviceManager instance; |
||||
private SearchResult allModelList; |
||||
|
||||
public static ComplementAdviceManager getInstance() { |
||||
if (instance == null) { |
||||
synchronized (ComplementAdviceManager.class) { |
||||
if (instance == null) { |
||||
instance = new ComplementAdviceManager(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
/** |
||||
* 从接口中获取补全建议结果 |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public SearchResult getAllSearchResult(String[] searchText) { |
||||
allModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { |
||||
SearchResult searchResult = new SearchResult(); |
||||
for (int j = 0; j < searchText.length; j++) { |
||||
String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + searchText[j]); |
||||
String url = AlphaFineConstants.COMPLEMENT_ADVICE_SEARCH_URL_PREFIX + "msg=" + searchText[j] + "&token=" + token; |
||||
try { |
||||
String result = HttpToolbox.get(url); |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); |
||||
if(jsonArray != null){ |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONObject jsonObject = jsonArray.optJSONObject(i); |
||||
|
||||
String temp = jsonObject.optString("keywords"); |
||||
if (StringUtils.isNotEmpty(temp)) { |
||||
RobotModel robotModel = new RobotModel(temp, null); |
||||
if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) { |
||||
allModelList.add(robotModel); |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("complement advice search error: " + e.getMessage()); |
||||
}catch (IOException e1) { |
||||
FineLoggerFactory.getLogger().error("complement advice get result error: " + e1.getMessage()); |
||||
} |
||||
} |
||||
if (searchResult.isEmpty()) { |
||||
return allModelList; |
||||
} else { |
||||
allModelList.addAll(searchResult); |
||||
} |
||||
} |
||||
return allModelList; |
||||
} |
||||
} |
@ -0,0 +1,151 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.RobotModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.JSONUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StringUtils; |
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class HotIssuesManager { |
||||
private static volatile HotIssuesManager instance; |
||||
private static final int HOT_ITEM_NUM = 6; |
||||
private static final int HOT_SUB_ITEM_NUM = 4; |
||||
private static final String HOT_ITEM = "item"; |
||||
private static final String HOT_ITEM_DATA = "itemData"; |
||||
private static final String HOT_ITEM_TEXT = "text"; |
||||
private static final String HOT_TYPE = "type"; |
||||
private static final String HOT_DATA = "data"; |
||||
|
||||
public static HotIssuesManager getInstance() { |
||||
if (instance == null) { |
||||
synchronized (HotIssuesManager.class) { |
||||
if (instance == null) { |
||||
instance = new HotIssuesManager(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
String[][] data = new String[HOT_ITEM_NUM][]; |
||||
Map<String, List> map = new HashMap<>(); |
||||
|
||||
/** |
||||
* 将子标题下的数据塞入modeList |
||||
* @param subTitle |
||||
* @return |
||||
*/ |
||||
public SearchResult getTitleSearchResult(String subTitle) { |
||||
SearchResult modeList = new SearchResult(); |
||||
modeList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText((subTitle)))); |
||||
|
||||
List<String> issueList = map.get(subTitle); |
||||
for (int i = 0; i < issueList.size(); i++) { |
||||
RobotModel robotModel = new RobotModel(issueList.get(i), null); |
||||
robotModel.setHotItemModel(true); |
||||
modeList.add(robotModel); |
||||
} |
||||
return modeList; |
||||
} |
||||
|
||||
/** |
||||
* 从热门问题接口获取热门问题 |
||||
* @return |
||||
*/ |
||||
public String[][] getHotIssues() { |
||||
|
||||
try { |
||||
String result = HttpToolbox.get(AlphaFineConstants.ALPHA_HOT_SEARCH); |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); |
||||
if(jsonArray != null){ |
||||
for (int i = 0; i < HOT_ITEM_NUM; i++) { |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONObject jsonObject = jsonArray.optJSONObject(i); |
||||
data[i] = getTitleStrings(jsonObject); |
||||
} |
||||
} |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("hotissues search error: " + e.getMessage()); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error("hotissues search get result error: " + e.getMessage()); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
/** |
||||
* 根据子标题获取该标题下数据 |
||||
* @param jsonObject |
||||
* @return |
||||
*/ |
||||
private String[] getTitleStrings(JSONObject jsonObject) { |
||||
String[] temp = getSubTitleFromCloud(jsonObject.optJSONObject(HOT_DATA)); |
||||
String[] temp1 = new String[1]; |
||||
temp1[0] = jsonObject.optString(HOT_TYPE); |
||||
int strLen1 = temp.length; |
||||
int strLen2 = temp1.length; |
||||
|
||||
temp1 = Arrays.copyOf(temp1, strLen2 + strLen1); |
||||
System.arraycopy(temp, 0, temp1, strLen2, strLen1); |
||||
|
||||
getIssueStrings(jsonObject.optJSONObject(HOT_DATA)); |
||||
|
||||
return temp1; |
||||
} |
||||
|
||||
/** |
||||
* 获取子标题和子标题下的问题列表 |
||||
* @param data |
||||
* @return |
||||
*/ |
||||
private void getIssueStrings(JSONObject data) { |
||||
try { |
||||
for (int j = 0; j < HOT_SUB_ITEM_NUM; j++) { |
||||
String temp = data.getString(HOT_ITEM + (j + 1)); |
||||
JSONArray jsonArray = data.getJSONArray(HOT_ITEM_DATA + (j + 1)); |
||||
List<String> tempList = new ArrayList<>(); |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
tempList.add(jsonArray.optJSONObject(i).optString(HOT_ITEM_TEXT)); |
||||
} |
||||
map.put(temp, tempList); |
||||
} |
||||
|
||||
} catch (JSONException e) { |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取问题列表 |
||||
* @param data |
||||
* @return |
||||
*/ |
||||
private String[] getSubTitleFromCloud(JSONObject data) { |
||||
ArrayList<String> list = new ArrayList<>(); |
||||
for (int i = 0; i < HOT_SUB_ITEM_NUM; i++) { |
||||
String temp = data.optString(HOT_ITEM + (i + 1)); |
||||
if (!StringUtils.isEmpty(temp)) { |
||||
list.add(temp); |
||||
} |
||||
} |
||||
String[] strings = new String[list.size()]; |
||||
list.toArray(strings); |
||||
return strings; |
||||
} |
||||
} |
@ -0,0 +1,82 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import com.fr.third.ibm.icu.text.BreakIterator; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class SegmentationManager { |
||||
private static volatile SegmentationManager segmentationManager = null; |
||||
private static final int MAX_CHINESE_CHARACTERS_NUM = 4; |
||||
|
||||
public static SegmentationManager getInstance() { |
||||
if (segmentationManager == null) { |
||||
synchronized (SegmentationManager.class) { |
||||
if (segmentationManager == null) { |
||||
segmentationManager = new SegmentationManager(); |
||||
} |
||||
} |
||||
} |
||||
return segmentationManager; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否需要分词 |
||||
* |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public boolean isNeedSegmentation(String searchText) { |
||||
int count = 0; |
||||
Pattern p = Pattern.compile(AlphaFineConstants.CHINESE_CHARACTERS); |
||||
Matcher m = p.matcher(searchText); |
||||
while (m.find()) { |
||||
for (int i = 0; i <= m.groupCount(); i++) { |
||||
count = count + 1; |
||||
} |
||||
} |
||||
if (count >= MAX_CHINESE_CHARACTERS_NUM) { |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
/** |
||||
* 对字符串进行分词 |
||||
* |
||||
* @param searchText |
||||
* @return |
||||
*/ |
||||
public String[] startSegmentation(String searchText) { |
||||
Pattern p = Pattern.compile(AlphaFineConstants.SPECIAL_CHARACTER_REGEX); |
||||
Matcher m = p.matcher(searchText); |
||||
searchText = m.replaceAll(StringUtils.EMPTY).trim().replaceAll(StringUtils.BLANK, StringUtils.EMPTY); |
||||
if (StringUtils.isEmpty(searchText)) { |
||||
return null; |
||||
} |
||||
if (!isNeedSegmentation(searchText)) { |
||||
return new String[]{searchText}; |
||||
} |
||||
List<String> result = new ArrayList<>(); |
||||
BreakIterator itor = BreakIterator.getWordInstance(); |
||||
itor.setText(searchText); |
||||
int start = itor.first(); |
||||
for (int end = itor.next(); end != BreakIterator.DONE; start = end, end = itor.next()) { |
||||
String temp = searchText.substring(start, end); |
||||
if (!StringUtils.isEmpty(temp)) { |
||||
result.add(temp); |
||||
} |
||||
} |
||||
String[] strings = new String[result.size()]; |
||||
result.toArray(strings); |
||||
return strings; |
||||
} |
||||
} |
@ -0,0 +1,100 @@
|
||||
package com.fr.design.mainframe.alphafine.search.manager.impl; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineConstants; |
||||
import com.fr.design.mainframe.alphafine.AlphaFineHelper; |
||||
import com.fr.design.mainframe.alphafine.CellType; |
||||
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
||||
import com.fr.design.mainframe.alphafine.cell.model.RobotModel; |
||||
import com.fr.design.mainframe.alphafine.model.SearchResult; |
||||
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
||||
import com.fr.general.http.HttpToolbox; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONException; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.json.JSONUtils; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import java.io.IOException; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
|
||||
/** |
||||
* Created by alex.sung on 2018/8/3. |
||||
*/ |
||||
public class SimilarSearchManeger implements AlphaFineSearchProvider { |
||||
private static volatile SimilarSearchManeger instance; |
||||
private SearchResult lessModelList; |
||||
private SearchResult moreModelList = new SearchResult(); |
||||
|
||||
public static SimilarSearchManeger getInstance() { |
||||
if (instance == null) { |
||||
synchronized (SimilarSearchManeger.class){ |
||||
if (instance == null) { |
||||
instance = new SimilarSearchManeger(); |
||||
} |
||||
} |
||||
} |
||||
return instance; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getLessSearchResult(String[] searchText) { |
||||
lessModelList = new SearchResult(); |
||||
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedIntelligentCustomerService()) { |
||||
SearchResult allModelList = new SearchResult(); |
||||
for (int j = 0; j < searchText.length; j++) { |
||||
String token = DigestUtils.md5Hex(AlphaFineConstants.ALPHA_ROBOT_SEARCH_TOKEN + searchText[j]); |
||||
String url = AlphaFineConstants.SIMILAR_SEARCH_URL_PREFIX + "msg=" + searchText[j] + "&token=" + token; |
||||
try { |
||||
String result = HttpToolbox.get(url); |
||||
AlphaFineHelper.checkCancel(); |
||||
JSONArray jsonArray = (JSONArray)JSONUtils.jsonDecode(result); |
||||
if(jsonArray != null){ |
||||
if (jsonArray.length() != 0) { |
||||
for (int i = 0; i < jsonArray.length(); i++) { |
||||
JSONObject jsonObject = jsonArray.optJSONObject(i); |
||||
String title = jsonObject.optString("title"); |
||||
RobotModel robotModel = new RobotModel(title, null); |
||||
if (!AlphaFineHelper.getFilterResult().contains(robotModel) && !allModelList.contains(robotModel)) { |
||||
allModelList.add(robotModel); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} catch (JSONException e) { |
||||
FineLoggerFactory.getLogger().error("similar search error: " + e.getMessage()); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error("similar search get result error: " + e.getMessage()); |
||||
} |
||||
} |
||||
moreModelList.clear(); |
||||
if (allModelList.isEmpty()) { |
||||
return lessModelList; |
||||
} else if (allModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) { |
||||
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Relation_Item"))); |
||||
lessModelList.addAll(allModelList); |
||||
} else { |
||||
lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Relation_Item"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.ROBOT)); |
||||
lessModelList.addAll(allModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
||||
moreModelList.addAll(allModelList.subList(AlphaFineConstants.SHOW_SIZE, allModelList.size())); |
||||
} |
||||
} |
||||
return lessModelList; |
||||
} |
||||
|
||||
@Override |
||||
public SearchResult getMoreSearchResult(String searchText) { |
||||
return moreModelList; |
||||
} |
||||
|
||||
/** |
||||
* 根据json信息获取RobotModel |
||||
* |
||||
* @param object |
||||
* @return |
||||
*/ |
||||
public static RobotModel getModelFromCloud(JSONObject object) { |
||||
String name = object.optString("title"); |
||||
String content = object.optString("content"); |
||||
return new RobotModel(name, content); |
||||
} |
||||
} |
After Width: | Height: | Size: 248 B |
After Width: | Height: | Size: 303 B |
After Width: | Height: | Size: 372 B |
After Width: | Height: | Size: 618 B |
After Width: | Height: | Size: 789 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 634 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 506 B |
After Width: | Height: | Size: 828 B |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 279 B |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 488 B |