From 5430083bec2d25d1ef94441f6017b210a6e7abbf Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Wed, 11 Jul 2018 21:17:20 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-9446=20=E3=80=9010.0=E4=B8=80=E8=BD=AE?= =?UTF-8?q?=E5=9B=9E=E5=BD=92=E3=80=91alphafine=E6=90=9C=E4=B8=8D=E5=87=BA?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=B8=B8=E7=94=A8=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/impl/RecentSearchManager.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java index ae937b53e..b67f4575f 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/RecentSearchManager.java @@ -63,6 +63,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider { public synchronized static RecentSearchManager getInstance() { if (recentSearchManager == null) { recentSearchManager = new RecentSearchManager(); + recentSearchManager.initWriter(); } return recentSearchManager; } @@ -95,17 +96,13 @@ public class RecentSearchManager implements AlphaFineSearchProvider { * 初始化indexWriter */ private void initWriter() { - if (indexWriter == null) { - try { - directory = FSDirectory.open(new File(path)); - } catch (IOException e) { - FineLoggerFactory.getLogger().error("cannot open directory " + path); - } - try { - indexWriter = new IndexWriter(directory, config); - } catch (IOException e) { - FineLoggerFactory.getLogger().error("not privilege to write to" + path); - } + try { + File file = new File(path); + StableUtils.mkdirs(file); + directory = FSDirectory.open(file); + indexWriter = new IndexWriter(directory, config); + } catch (IOException e) { + FineLoggerFactory.getLogger().error("not privilege to write to" + path); } } @@ -116,9 +113,8 @@ public class RecentSearchManager implements AlphaFineSearchProvider { private void initReader() { if (indexReader == null) { try { - File file = new File(path); - StableUtils.mkdirs(file); - directory = FSDirectory.open(file); + indexWriter.close(); + directory = FSDirectory.open(new File(path)); indexReader = DirectoryReader.open(directory); } catch (IOException e) { FineLoggerFactory.getLogger().error("not privilege to read " + path); @@ -169,6 +165,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider { private synchronized SearchResult searchBySort(String key) { recentModelList = new SearchResult(); try { + initReader(); IndexSearcher searcher = new IndexSearcher(indexReader); //构建排序字段