package jim.testLucene2; import java.io.File; import java.io.IOException; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.Field.Index; import org.apache.lucene.document.Field.Store; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.Term; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.wltea.analyzer.lucene.IKAnalyzer; public class testLcuene2 { public static void main(String[] args) throws IOException { String[] num = {"1","2","3","4"}; String[] emial = {"jim@tom.com","zhai@tom.com","jimzhai@tom.com","love@tom.com"}; String[] name = {"jim","zhai","john","tom"}; String[] contents = {"Hello jim","Hello zhai","Hello jhon","Hello tom"}; Directory directory = FSDirectory.open(new File("index")); IndexWriter writer = new IndexWriter(directory, new IndexWriterConfig(Version.LUCENE_35,new IKAnalyzer())); Document doc = null; Field field = null; for(int i = 0 ; i < num.length ; i++){ doc = new Document(); field = new Field("num",num[i],Store.YES,Index.NOT_ANALYZED_NO_NORMS); doc.add(field); field = new Field("emial",emial[i],Store.YES,Index.NOT_ANALYZED); doc.add(field); field = new Field("name",name[i],Store.YES,Index.NOT_ANALYZED_NO_NORMS); doc.add(field); field = new Field("content",contents[i],Store.YES,Index.ANALYZED); doc.add(field); writer.addDocument(doc); System.out.println(num[i]+" has indexed"); } writer.close(); IndexReader reader =IndexReader.open(directory); System.out.println("reader.numDocs():"+reader.numDocs()+" reader.maxDocs(): "+reader.maxDoc()); writer = new IndexWriter(directory,new IndexWriterConfig(Version.LUCENE_35,new IKAnalyzer())); writer.deleteDocuments(new Term("num","1")); System.out.println("reader.numDocs():"+reader.numDocs()+" reader.maxDocs(): "+reader.maxDoc()); writer.close(); reader.close(); } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class testIterator { public static void main(String [] args) throws IOException{ int num = 0; List myList = new ArrayList(); BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in)); String mm = null; mm = myIn.readLine(); while(!mm.equals("exit")){ num = Integer.parseInt(mm); myList.add(num); mm = myIn.readLine(); } myIn.close(); Iterator Iter = myList.iterator(); while(Iter.hasNext()){ System.out.println(Iter.next()); } } }
今天的收获:
对lucene跟加熟悉了
今天的不足:
对数据解析还是不了解
每日一练
最新推荐文章于 2023-08-08 15:03:33 发布