|
|
@ -63,6 +63,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
public synchronized static RecentSearchManager getInstance() { |
|
|
|
public synchronized static RecentSearchManager getInstance() { |
|
|
|
if (recentSearchManager == null) { |
|
|
|
if (recentSearchManager == null) { |
|
|
|
recentSearchManager = new RecentSearchManager(); |
|
|
|
recentSearchManager = new RecentSearchManager(); |
|
|
|
|
|
|
|
recentSearchManager.initWriter(); |
|
|
|
} |
|
|
|
} |
|
|
|
return recentSearchManager; |
|
|
|
return recentSearchManager; |
|
|
|
} |
|
|
|
} |
|
|
@ -95,17 +96,13 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
* 初始化indexWriter |
|
|
|
* 初始化indexWriter |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void initWriter() { |
|
|
|
private void initWriter() { |
|
|
|
if (indexWriter == null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
File file = new File(path); |
|
|
|
directory = FSDirectory.open(new File(path)); |
|
|
|
StableUtils.mkdirs(file); |
|
|
|
} catch (IOException e) { |
|
|
|
directory = FSDirectory.open(file); |
|
|
|
FineLoggerFactory.getLogger().error("cannot open directory " + path); |
|
|
|
indexWriter = new IndexWriter(directory, config); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
try { |
|
|
|
FineLoggerFactory.getLogger().error("not privilege to write to" + path); |
|
|
|
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() { |
|
|
|
private void initReader() { |
|
|
|
if (indexReader == null) { |
|
|
|
if (indexReader == null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
File file = new File(path); |
|
|
|
indexWriter.close(); |
|
|
|
StableUtils.mkdirs(file); |
|
|
|
directory = FSDirectory.open(new File(path)); |
|
|
|
directory = FSDirectory.open(file); |
|
|
|
|
|
|
|
indexReader = DirectoryReader.open(directory); |
|
|
|
indexReader = DirectoryReader.open(directory); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
FineLoggerFactory.getLogger().error("not privilege to read " + path); |
|
|
|
FineLoggerFactory.getLogger().error("not privilege to read " + path); |
|
|
@ -169,6 +165,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
private synchronized SearchResult searchBySort(String key) { |
|
|
|
private synchronized SearchResult searchBySort(String key) { |
|
|
|
recentModelList = new SearchResult(); |
|
|
|
recentModelList = new SearchResult(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
initReader(); |
|
|
|
initReader(); |
|
|
|
IndexSearcher searcher = new IndexSearcher(indexReader); |
|
|
|
IndexSearcher searcher = new IndexSearcher(indexReader); |
|
|
|
//构建排序字段
|
|
|
|
//构建排序字段
|
|
|
|