|
|
@ -45,7 +45,7 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
private static final int MAX_SIZE = 3; |
|
|
|
private static final int MAX_SIZE = 3; |
|
|
|
private static RecentSearchManager recentSearchManager = null; |
|
|
|
private static RecentSearchManager instance; |
|
|
|
IndexReader indexReader = null; |
|
|
|
IndexReader indexReader = null; |
|
|
|
IndexSearcher indexSearcher = null; |
|
|
|
IndexSearcher indexSearcher = null; |
|
|
|
//索引存储路径
|
|
|
|
//索引存储路径
|
|
|
@ -59,11 +59,16 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
private SearchResult recentModelList; |
|
|
|
private SearchResult recentModelList; |
|
|
|
private SearchResult modelList; |
|
|
|
private SearchResult modelList; |
|
|
|
|
|
|
|
|
|
|
|
public synchronized static RecentSearchManager getInstance() { |
|
|
|
public static RecentSearchManager getInstance() { |
|
|
|
if (recentSearchManager == null) { |
|
|
|
if (instance == null) { |
|
|
|
recentSearchManager = new RecentSearchManager(); |
|
|
|
synchronized (RecentSearchManager.class) { |
|
|
|
|
|
|
|
if (instance == null) { |
|
|
|
|
|
|
|
instance = new RecentSearchManager(); |
|
|
|
|
|
|
|
instance.initWriter(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return recentSearchManager; |
|
|
|
return instance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -94,17 +99,11 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
* 初始化indexWriter |
|
|
|
* 初始化indexWriter |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void initWriter() { |
|
|
|
private void initWriter() { |
|
|
|
if (indexWriter == null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
directory = FSDirectory.open(new File(path)); |
|
|
|
directory = FSDirectory.open(new File(path)); |
|
|
|
indexWriter = new IndexWriter(directory, config); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
FineLoggerFactory.getLogger().error("cannot open directory " + path); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
indexWriter = new IndexWriter(directory, config); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error("not privilege to write to" + path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -113,20 +112,18 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
* 初始化indexReader |
|
|
|
* 初始化indexReader |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void initReader() { |
|
|
|
private void initReader() { |
|
|
|
if (indexReader == null) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
indexWriter.close(); |
|
|
|
directory = FSDirectory.open(new File(path)); |
|
|
|
indexReader = DirectoryReader.open(directory); |
|
|
|
indexReader = DirectoryReader.open(directory); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error("not privilege to read " + path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
indexSearcher = new IndexSearcher(indexReader); |
|
|
|
indexSearcher = new IndexSearcher(indexReader); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 添加模型 |
|
|
|
* 添加模型 |
|
|
|
|
|
|
|
* |
|
|
|
* @param searchKey |
|
|
|
* @param searchKey |
|
|
|
* @param cellModel |
|
|
|
* @param cellModel |
|
|
|
* @param searchCount |
|
|
|
* @param searchCount |
|
|
@ -146,6 +143,7 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 写文档,建立索引 |
|
|
|
* 写文档,建立索引 |
|
|
|
|
|
|
|
* |
|
|
|
* @param doc |
|
|
|
* @param doc |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void writeDoc(Document doc) { |
|
|
|
private void writeDoc(Document doc) { |
|
|
@ -160,12 +158,14 @@ public class RecentSearchManager implements AlphaFineSearchProvider { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 按序搜索 |
|
|
|
* 按序搜索 |
|
|
|
|
|
|
|
* |
|
|
|
* @param key |
|
|
|
* @param key |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
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); |
|
|
|
//构建排序字段
|
|
|
|
//构建排序字段
|
|
|
|