package luceneQuery; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Date; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TermRangeQuery; import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.spans.SpanFirstQuery; import org.apache.lucene.search.spans.SpanNearQuery; import org.apache.lucene.search.spans.SpanNotQuery; import org.apache.lucene.search.spans.SpanOrQuery; import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.SpanTermQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.RAMDirectory; public class QueryTest { static String sIndex_Path="E:/index"; static String sText_path="E:/textbook"; static protected String[] keywords = {"001","002","003","004","005"}; static protected String[] textdetail = {"记录 一","记录 二","记录 三","一 2345 记录","记录 新 一"}; static File fIndex_Path=new File(sIndex_Path); /**=========================================================== * 名称:IndexBuilder * 功能:构造磁盘索引,添加内容到指定目录,为后继检索查询做好准备 =============================================================**/ public static void IndexBuilder(){ try{ Date start = new Date(); File f=new File(sText_path); File[] list=f.listFiles(); File file2 = new File(sIndex_Path); //创建磁盘索引目录 Directory dir = FSDirectory.open(file2); Directory ramdir = new RAMDirectory(); Analyzer TextAnalyzer = new SimpleAnalyzer(); //创建磁盘索引 IndexWriter TextIndex = new IndexWriter(dir, TextAnalyzer, true, IndexWriter.MaxFieldLength.LIMITED); //创建内存索引 IndexWriter RAMTextIndex = new IndexWriter(ramdir,TextAnalyzer,true, IndexWriter.MaxFieldLength.LIMITED); for(int i=0;i