资源简介
lucene对某目录下txt文件做全文检索源码
代码片段和文件信息
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Date;
import java.util.List;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.SimpleAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.codecs.TermVectorsReader;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Store;
import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Fields;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.SlowCompositeReaderWrapper;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermContext;
import org.apache.lucene.index.TermState;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermStatistics;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
public class TestIndexReadWrite {
/**
* @param args
* @throws IOException
*/
public static void buildIndex(String fileDirString indexDir) throws IOException{
//fileDir is the directory that contains the text files to be indexed
//indexDir is the directory that hosts Lucene‘s index files
File textFile = new File(fileDir);
File indexFile = new File(indexDir);
Directory dir=FSDirectory.open(indexFile);
//Analyzer luceneAnalyzer = new StandardAnalyzer(Version.LUCENE_42);
Analyzer luceneAnalyzer = new SimpleAnalyzer(Version.LUCENE_42);
IndexWriterConfig iwc=new IndexWriterConfig(Version.LUCENE_42luceneAnalyzer);
IndexWriter indexWriter = new IndexWriter(diriwc);
File[] textFiles = textFile.listFiles();
long startTime = new Date().getTime();
//Add documents to the index
for(int i = 0; i < textFiles.length; i++){
if(textFiles[i].isFile()&& textFiles[i].getName().endsWith(“.txt“)){
System.out.println(“File “ + textFiles[i].getCanonicalPath()
+ “ is being indexed“);
Reader textReader = new FileReader(textFiles[i]);
- 上一篇:java课程设计实验报告
- 下一篇:SurfaceControl.jar
相关资源
- lucene3.0 整合庖丁解牛
- IKAnalyzer中文分词支持lucene6.5.0版本
- indexer-cli-5.1.1.jar-maven 索引解压工具
- Lucene搜索引擎 JSP + JAVA
- IK Analyzer支持Lucene6.0以上版本
- lucene 全文检索系统 java源码 信息检
- Lucene提取新闻关键词Top-N
- lucene4.0常用jar包
- 基于java的文本搜索引擎的设计与实现
- android和lucene组合实现全文检索代码
- lucene-core-3.6.1.jar
- lucene-core-3.6.0.jar
- 中文分词库 IKAnalyzer For Lucene 5.2.1适用
- lucene-core-3.6.2.jar
- lucene全文检索需要jar包
- lucene-core-2.4.1.jar
- IK-Analyzer-4.10.1.jar
- lucene4.6所有jar包
- 最全的lucene-2.4.0jar包
- Java Web+爬虫+lucene 大学新闻网
- Lucene项目(华电内部文档搜索系统)
- 解密搜索引擎技术实战Lucene&Java精华版
- 解密搜索引擎技术实战Lucene&Java精华版
- lucene3.0.0jar及IKAnalyzer
- Lucene实现小型信息检索系统
- 基于Lucene的小型搜索引擎
- Lucene7.0.1 中文完整Jar包 包含所有jar
- lucene4.6.0所有jar包集合
- lucene检索代码,自己总结的非常详细
- 解密搜索引擎技术实战Lucene&Java精华版
评论
共有 条评论