Browse Source

REPORT-9819

【10.0二轮回归】alphafine搜索模板打开后,再次搜索会增加多个重复模板的搜索结果
final/10.0
XiaXiang 7 years ago
parent
commit
37e1ddadc2
  1. 41
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  2. 21
      designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java

41
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -28,10 +28,11 @@ import com.fr.design.mainframe.alphafine.search.manager.impl.FileSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.PluginSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.impl.RecommendSearchManager;
import com.fr.design.mainframe.errorinfo.ErrorInfoUploader;
import com.fr.design.mainframe.templateinfo.TemplateInfoCollector;
import com.fr.form.main.Form;
import com.fr.form.main.FormIO;
import com.fr.general.ComparatorUtils;
import com.fr.general.http.HttpClient;
import com.fr.io.TemplateWorkBookIO;
import com.fr.io.exporter.ImageExporter;
@ -44,11 +45,28 @@ import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.event.DocumentEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -761,11 +779,18 @@ public class AlphaFineDialog extends UIDialog {
*
* @param cellModel
*/
private void saveLocalHistory(AlphaCellModel cellModel) {
RecentSearchManager searchManager = RecentSearchManager.getInstance();
searchManager.addModel(storeText, cellModel, cellModel.getSearchCount() + 1);
sendDataToServer(storeText, cellModel);
private void saveLocalHistory(final AlphaCellModel cellModel) {
Thread sendThread = new Thread(new Runnable() {
@Override
public void run() {
RecentSearchManager searchManager = RecentSearchManager.getInstance();
searchManager.addModel(storeText, cellModel);
sendDataToServer(storeText, cellModel);
TemplateInfoCollector.getInstance().sendTemplateInfo();
ErrorInfoUploader.getInstance().sendErrorInfo();
}
});
sendThread.start();
}
/**

21
designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe.alphafine.search.manager.impl;
import com.fr.design.actions.UpdateAction;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.model.ActionModel;
@ -9,7 +10,6 @@ import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider;
import com.fr.design.mainframe.toolbar.UpdateActionManager;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.log.FineLoggerFactory;
@ -18,7 +18,7 @@ import com.fr.third.org.apache.lucene.analysis.Analyzer;
import com.fr.third.org.apache.lucene.analysis.standard.StandardAnalyzer;
import com.fr.third.org.apache.lucene.document.Document;
import com.fr.third.org.apache.lucene.document.Field;
import com.fr.third.org.apache.lucene.document.IntField;
import com.fr.third.org.apache.lucene.document.LongField;
import com.fr.third.org.apache.lucene.document.StringField;
import com.fr.third.org.apache.lucene.index.DirectoryReader;
import com.fr.third.org.apache.lucene.index.IndexReader;
@ -78,7 +78,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider {
if (recentModelList != null && recentModelList.size() > 0) {
modelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_Latest")));
}
modelList.addAll(recentModelList);
modelList.addAll(recentModelList.subList(0, AlphaFineConstants.LATEST_SHOW_SIZE));
return modelList;
}
@ -126,15 +126,14 @@ public class RecentSearchManager implements AlphaFineSearchProvider {
*
* @param searchKey
* @param cellModel
* @param searchCount
*/
public void addModel(String searchKey, AlphaCellModel cellModel, int searchCount) {
public void addModel(String searchKey, AlphaCellModel cellModel) {
try {
initWriter();
Document doc = new Document();
doc.add(new StringField("searchKey", searchKey, Field.Store.YES));
doc.add(new StringField("cellModel", cellModel.ModelToJson().toString(), Field.Store.YES));
doc.add(new IntField("searchCount", searchCount, Field.Store.YES));
doc.add(new LongField("time", System.currentTimeMillis(), Field.Store.YES));
writeDoc(doc);
} catch (JSONException e) {
FineLoggerFactory.getLogger().error("add document error: " + e.getMessage());
@ -170,12 +169,12 @@ public class RecentSearchManager implements AlphaFineSearchProvider {
IndexSearcher searcher = new IndexSearcher(indexReader);
//构建排序字段
SortField[] sortField = new SortField[1];
sortField[0] = new SortField("searchCount", SortField.Type.INT, true);
sortField[0] = new SortField("time", SortField.Type.LONG, true);
Sort sortKey = new Sort(sortField);
String searchField = "searchKey";
Term term = new Term(searchField, key);
Query query = new TermQuery(term);
TopFieldDocs docs = searcher.search(query, MAX_SIZE, sortKey);
TopFieldDocs docs = searcher.search(query, 100, sortKey);
ScoreDoc[] scores = docs.scoreDocs;
this.recentModelList = new SearchResult();
//遍历结果
@ -186,9 +185,15 @@ public class RecentSearchManager implements AlphaFineSearchProvider {
UpdateAction action = UpdateActionManager.getUpdateActionManager().getActionByName(model.getName());
if (action != null) {
((ActionModel) model).setAction(action);
if (recentModelList.contains(model)) {
continue;
}
recentModelList.add(model);
}
} else {
if (recentModelList.contains(model)) {
continue;
}
recentModelList.add(model);
}

Loading…
Cancel
Save