/**
* @se 搜索列表显示
* @param paginator
* @param initData
* @return List
* @throws Exception
*/
@SuppressWarnings("unchecked")
public List searchEppendActiveList(Pagination paginator, Map initData)
throws Exception {
IndexSearcher indexSearcher = LuceneUtils
.getEmpuserbaseSearcher(LuceneUtils
.getEmpuserActivityPathDirectory());
if (null == indexSearcher)
return null;
BooleanQuery booleanQuery = new BooleanQuery();
Query query = null;
int firstType = Integer.parseInt(initData.get("type").toString());
if (firstType > 0) {
query = new TermQuery(new Term(Constants.TYPE, String
.valueOf(firstType)));
booleanQuery.add(query, BooleanClause.Occur.MUST);
}
// 数据标志
query = new TermQuery(new Term(Constants.TOTALDATA, String.valueOf(1)));
booleanQuery.add(query, BooleanClause.Occur.MUST);
// 排序
Sort sort = new Sort();
ScoreDoc[] hits = indexSearcher.search(booleanQuery, null, 1000, sort).scoreDocs;
int score = null == hits ? 0 : hits.length;
paginator.setTotalCount(score);
return eppendActiveDataList(hits, paginator, indexSearcher);
}
/**
* @see 返回数据list封装
* @param hits
* @param paginator
* @param queryKey
* @return list
*/
@SuppressWarnings("unchecked")
private List eppendActiveDataList(ScoreDoc[] hits, Pagination paginator,
IndexSearcher indexSearcher) throws Exception {
List objList = new ArrayList();
for (int i = (paginator.getPageNo() - 1) * paginator.getRowsPerPage(); i < (paginator
.getPageNo())
* paginator.getRowsPerPage()
&& i < hits.length; i++) {
Document doc = indexSearcher.doc(hits[i].doc);
Object[] obj = new Object[7];
// 活动id
obj[0] = doc.get(Constants.ID);
// 活动标题
obj[1] = doc.get(Constants.USERCODE);
// 日期
obj[2] = doc.get(Constants.NICKNAME);
objList.add(obj);
}
return objList;
}
package test;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.SimpleFSDirectory;
public class LuceneUtils {
private static String eppendActivityPath = "D:/index/empuserbase";
private static Directory empuserActivityPathDirectory;
public static Directory getEmpuserActivityPathDirectory() {
if (null == empuserActivityPathDirectory)
setEmpuserActivityPathDirectory(readDirectory(
empuserActivityPathDirectory, eppendActivityPath));
return empuserActivityPathDirectory;
}
public static void setEmpuserActivityPathDirectory(
Directory empuserActivityPathDirectory) {
LuceneUtils.empuserActivityPathDirectory = empuserActivityPathDirectory;
}
/**
* @see 读取文件目录,首先尝试建立内存索引文件,不成功则从硬盘读取
*/
private static Directory readDirectory(Directory dest, String path) {
System.out.println("目录:" + dest);
if (dest != null) {
return dest;
} else {
try {
dest = new RAMDirectory(new SimpleFSDirectory(new File(path)));
System.out.println("将" + path + "读入内存,当前时间:" + new Date());
} catch (IOException e) {
e.printStackTrace();
try {
dest = FSDirectory.open(new File(path));
} catch (IOException e1) {
e1.printStackTrace();
return null;
}
}
return dest;
}
}
private volatile static IndexSearcher empuserbaseSearcher;
public synchronized static IndexSearcher getEmpuserbaseSearcher(
Directory directory) {
if (empuserbaseSearcher == null) {
try {
System.out.println("新建empuserbaseSearcher实例");
synchronized (eppendActivityPath) {
if (empuserbaseSearcher == null) {
empuserbaseSearcher = new IndexSearcher(directory);
}
}
} catch (CorruptIndexException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return empuserbaseSearcher;
}
}
分享到:
相关推荐
文件包括 :lucene-core-3.0.0.jar lucene-highlighter-3.0.0.jar lucene-memory-3.0.0.jar,mysql-connector-java-3.1.13-bin.jar,lucene-demos-1.9.1.jar lucene-core-1.9.1.jar
lucene需要用到的基本架包 核心包 高亮 中文分词,希望有所帮助。je-analysis1.5.3.jar lucene-highlighter-3.0.0.jar lucene-core-3.0.0.jar lucene-memory-3.0.0.jar
19 lucene-core-3.0.0.jar 搜索引擎 20 lucene-highlighter-3.0.0.jar 搜索引擎高亮处理 21 mail.jar 邮件核心包 22 mysql-connector-java-5.1.10-bin.jar MYSQL驱动包 23 slf4j-api-1.5.10.jar 日志包,EhCache...
`lucene-core-3.0.0.jar`是Lucene的核心库,它提供了构建搜索引擎的基本构建块。这个库包含了索引和搜索的主要类,如`Analyzer`用于文本分词,`IndexWriter`用于创建和更新索引,`IndexReader`用于读取索引,以及`...
lucene-core-3.0.0.jar是Lucene的核心库,包含了构建和查询索引的基本功能。 二、分词的重要性 中文分词是中文信息处理的基础,它将连续的汉字序列切分成具有独立语义的词语。对于搜索引擎而言,准确的分词能够提高...
3. **lucene-core-3.0.0.jar**:这就是Apache Lucene的核心库,包含索引和搜索功能的实现。 4. **poi-scratchpad-3.6-20091214.jar**:Apache POI库用于处理Microsoft Office文件,可能用于解析Excel表格中的医院...
1. **lucene-core-3.0.0.jar**:这是Apache Lucene的核心库,一个高性能的全文搜索引擎框架。它提供了文本分析、索引和查询的能力,使得开发者能够快速地在大量数据中搜索信息。 2. **mysql-connector-5.1.8.jar**...
6. **lucene-core-3.0.0.jar**:Apache Lucene 是一个高性能全文搜索引擎库,这里版本3.0.0用于实现OA系统中的文本检索功能。 7. **poi-scratchpad-3.6-20091214.jar**:POI Scratchpad 包含了对Microsoft Office...