From 38ded435a475c40cae45b6249a8f86af79c7a4a7 Mon Sep 17 00:00:00 2001 From: hades Date: Mon, 16 May 2022 10:43:06 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-70681=20=E8=B6=85=E9=95=BF=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E6=90=9C=E7=B4=A2=E9=97=AE=E9=A2=98=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A510.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alphafine/AlphaFineConstants.java | 11 ++++ .../alphafine/component/AlphaFineFrame.java | 65 ++++++++++++++----- .../manager/impl/ActionSearchManager.java | 9 ++- .../manager/impl/DocumentSearchManager.java | 11 ++++ 4 files changed, 79 insertions(+), 17 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index f4440fb5c..9ceec2a2f 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -48,6 +48,17 @@ public class AlphaFineConstants { public static final int HOT_ITEMS = 6; + /** + * 限制搜索字符长度 + */ + public static final int LEN_LIMIT = 50; + + /** + * 帮助文档搜索间隔(ms) api限制了1s之内只能搜索一次 + * + */ + public static final long DOCUMENT_SEARCH_GAP = 1000; + public static final Dimension FULL_SIZE = new Dimension(680, 460); diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineFrame.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineFrame.java index b6763f8cf..db89cf348 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineFrame.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineFrame.java @@ -146,6 +146,8 @@ public class AlphaFineFrame extends JFrame { private UILabel clearLabel; + private JPanel tabPane; + private CellType selectedType; private String beforeSearchStr = StringUtils.EMPTY; @@ -365,7 +367,7 @@ public class AlphaFineFrame extends JFrame { labelPane.add(labelContentPane); labelPane.setPreferredSize(new Dimension(AlphaFineConstants.FULL_SIZE.width, 30)); - JPanel tabPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 10)); + tabPane = new JPanel(new FlowLayout(FlowLayout.LEFT, 20, 10)); tabPane.setBackground(Color.WHITE); List selectedLabelList = createSelectedLabelList(); selectedType = selectedLabelList.get(0).getCellType(); @@ -624,6 +626,7 @@ public class AlphaFineFrame extends JFrame { clearLabel.setVisible(true); SearchTooltipPopup.getInstance().show(searchTextFieldWrapperPane); } + tabPane.repaint(); }); timer.start(); @@ -644,28 +647,58 @@ public class AlphaFineFrame extends JFrame { beforeSearchStr = StringUtils.EMPTY; return; } + String lowerCaseSearchText = preProcessSearchText(searchTextField.getText().toLowerCase()); if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isNeedSegmentationCheckbox()) { - //是高级搜索 - if (searchTextField.getText().toLowerCase().startsWith(ADVANCED_SEARCH_MARK)) { - segmentationResult = SegmentationManager.getInstance().startSegmentation(getStoreText(searchTextField.getText().toLowerCase())); - } - //是普通搜索 - else { - segmentationResult = SegmentationManager.getInstance().startSegmentation(searchTextField.getText().toLowerCase()); - } + dealSegmentationSearch(lowerCaseSearchText); } else { - if (StringUtils.isEmpty(getRealSearchText(searchTextField.getText()))) { - segmentationResult = null; - } else { - segmentationResult = new String[]{getRealSearchText(searchTextField.getText())}; - } + dealNormalSearch(); } DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().getHistorySearch().push(searchTextField.getText()); - doSearch(searchTextField.getText().toLowerCase()); + doSearch(lowerCaseSearchText); beforeSearchStr = searchTextField.getText(); SearchTooltipPopup.getInstance().hide(); } + /** + * 普通搜索 + */ + private void dealNormalSearch() { + String searchText = preProcessSearchText(searchTextField.getText()); + if (StringUtils.isEmpty(getRealSearchText(searchText))) { + segmentationResult = null; + } else { + segmentationResult = new String[]{getRealSearchText(searchText)}; + } + } + + /** + * 分词搜索 + */ + private void dealSegmentationSearch(String lowerCaseSearchText) { + //是高级搜索 + if (searchTextField.getText().toLowerCase().startsWith(ADVANCED_SEARCH_MARK)) { + segmentationResult = SegmentationManager.getInstance().startSegmentation(getStoreText(lowerCaseSearchText)); + } + //是普通搜索 + else { + segmentationResult = SegmentationManager.getInstance().startSegmentation(lowerCaseSearchText); + } + } + + /** + * 文本预处理 限制长度 + * + * @param text + * @return + */ + private String preProcessSearchText(String text) { + if (text.length() > AlphaFineConstants.LEN_LIMIT) { + return text.substring(0, AlphaFineConstants.LEN_LIMIT); + } else { + return text; + } + } + private void dealWithSearchResult() { final AlphaCellModel model = searchResultList.getSelectedValue(); if (model != null) { @@ -717,7 +750,7 @@ public class AlphaFineFrame extends JFrame { * */ private void reSearch() { - String text = this.searchTextField.getText().toLowerCase(); + String text = preProcessSearchText(this.searchTextField.getText().toLowerCase()); if (StringUtils.isEmpty(text)) { return; } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java index a2a1a7037..54d6d1402 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/ActionSearchManager.java @@ -17,7 +17,9 @@ import com.fr.json.JSONObject; import com.fr.stable.ArrayUtils; import com.fr.stable.StringUtils; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * Created by XiaXiang on 2017/3/27. @@ -68,12 +70,17 @@ public class ActionSearchManager implements AlphaFineSearchProvider { return lessModelList; } List updateActions = UpdateActionManager.getUpdateActionManager().getUpdateActions(); + Set searchKeySet = new HashSet<>(); for (UpdateActionModel updateActionModel : updateActions) { for (int j = 0; j < searchText.length; j++) { AlphaFineHelper.checkCancel(); if (StringUtils.isNotBlank(updateActionModel.getSearchKey())) { - if (updateActionModel.getSearchKey().contains(searchText[j]) && updateActionModel.getAction().isEnabled()) { + if (updateActionModel.getSearchKey().contains(searchText[j]) + && updateActionModel.getAction().isEnabled() + // 老alphaFine就有问题 加个去重 + && !searchKeySet.contains(updateActionModel.getSearchKey())) { filterModelList.add(new ActionModel(updateActionModel.getActionName(), updateActionModel.getParentName(), updateActionModel.getAction())); + searchKeySet.add(updateActionModel.getSearchKey()); } } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java index bc3b214d0..3ea1f2db2 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/DocumentSearchManager.java @@ -15,6 +15,7 @@ import com.fr.json.JSONException; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; +import java.util.concurrent.TimeUnit; /** @@ -67,6 +68,7 @@ public class DocumentSearchManager implements AlphaFineSearchProvider { } searchResult = new SearchResult(); for (int j = 0; j < searchText.length; j++) { + long start = System.currentTimeMillis(); String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText[j]; try { String result = HttpToolbox.get(url); @@ -88,6 +90,15 @@ public class DocumentSearchManager implements AlphaFineSearchProvider { } catch (Exception e) { FineLoggerFactory.getLogger().error("document search error: " + e.getMessage()); } + // 计算等待时间 防止1s内搜索多次 + long spentTime = (System.currentTimeMillis() - start); + long waitTime = AlphaFineConstants.DOCUMENT_SEARCH_GAP - spentTime; + if (waitTime > 0 && j != searchText.length - 1) { + try { + TimeUnit.MILLISECONDS.sleep(waitTime); + } catch (Exception ignored) { + } + } } lessModelList.clear(); moreModelList.clear();