锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲高清av,国产精品夜夜夜,国产成人97精品免费看片http://www.aygfsteel.com/javadragon/category/29097.htmldragonzh-cnMon, 21 Jan 2008 16:36:08 GMTMon, 21 Jan 2008 16:36:08 GMT60- lucene鏈鍩烘湰鐨勫叆闂ㄤ緥瀛?/title>http://www.aygfsteel.com/javadragon/archive/2008/01/21/176837.htmljavadragonjavadragonMon, 21 Jan 2008 13:02:00 GMThttp://www.aygfsteel.com/javadragon/archive/2008/01/21/176837.htmlhttp://www.aygfsteel.com/javadragon/comments/176837.htmlhttp://www.aygfsteel.com/javadragon/archive/2008/01/21/176837.html#Feedback0http://www.aygfsteel.com/javadragon/comments/commentRss/176837.htmlhttp://www.aygfsteel.com/javadragon/services/trackbacks/176837.html
package test;
import java.io.IOException;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.LockObtainFailedException;
import org.junit.Before;
import org.junit.Test;
/**
聽* @author dragon
聽*
聽*/
public class TestBase {
聽聽聽
聽聽聽 private String path;
聽聽聽 @Before
聽聽聽 public void init(){
聽聽聽 聽聽聽 path = "/home/dragon/application/mywork/lucenetest/index";
聽聽聽 }
聽聽聽
聽
//聽聽聽 @Test聽聽聽聽 // 鍒涘緩绱㈠紩鏂囦歡
聽聽聽 public void writerContent() throws CorruptIndexException, LockObtainFailedException, IOException{
聽聽聽 聽聽聽聽 // IndexWriter鐨勭涓変釜鍙傛暟涓篺alse鏃訛紝鍒欏湪宸叉湁鐨勭儲寮曟枃浠惰拷鍔犲唴瀹?br />聽聽聽 聽聽聽 IndexWriter writer = new IndexWriter(path, new SimpleAnalyzer(), true);
聽聽聽 聽聽聽
聽聽聽 聽聽聽
聽聽聽 聽聽聽 Document doc = new Document();
聽聽聽 聽聽聽 String text = "Figure out which ClassLoader to use.聽 For JDK 1.2 and later use the";
聽聽聽 聽聽聽 doc.add(new Field("content", text, Field.Store.YES, Field.Index.TOKENIZED));
聽聽聽 聽聽聽
聽聽聽 聽聽聽 Document doc2 = new Document();
聽聽聽 聽聽聽 String text2 = "context ClassLoader if possible.聽 Note: we defer linking the class";
聽聽聽 聽聽聽 doc.add(new Field("content", text2, Field.Store.YES, Field.Index.TOKENIZED));
聽聽聽 聽聽聽
聽聽聽 聽聽聽 Document doc3 = new Document();
聽聽聽 聽聽聽 String text3 = "that calls an API only in JDK 1.2 until runtime so that we can catch";
聽聽聽 聽聽聽 doc.add(new Field("content", text3, Field.Store.YES, Field.Index.TOKENIZED));
聽聽聽 聽聽聽
聽聽聽 聽聽聽 writer.addDocument(doc);
聽聽聽 聽聽聽 writer.addDocument(doc2);
聽聽聽 聽聽聽 writer.addDocument(doc3);
聽聽聽 聽聽聽 聽
聽聽聽 聽聽聽 writer.optimize();
聽聽聽 聽聽聽 writer.close();
聽聽聽 聽聽聽
聽聽聽 }
聽聽聽
聽聽聽 @Test聽聽 // 鎼滅儲鍖呭惈鍏抽敭瀛梜ey鐨勫唴瀹?br />聽聽聽 public void searchContent() throws IOException, ParseException{
聽聽聽 聽聽聽 Directory directory = FSDirectory.getDirectory(path);
聽聽聽 聽聽聽 IndexSearcher search = new IndexSearcher(directory);
聽聽聽 聽聽聽
聽聽聽 聽聽聽 String key = "use";
聽聽聽 聽聽聽 QueryParser parser = new QueryParser("content",new SimpleAnalyzer());
聽聽聽 聽聽聽 Query query = parser.parse(key);
聽聽聽 聽聽聽
聽聽聽 聽聽聽 Hits hits = search.search(query);
聽聽聽 聽聽聽
聽聽聽 聽聽聽 for(int i = 0; i < hits.length(); i++){
聽聽聽 聽聽聽 聽聽聽 Document doc = hits.doc(i);
聽聽聽 聽聽聽 聽聽聽 System.out.println(" 鏌ヨ緇撴灉 : "+ doc.get("content"));
聽聽聽 聽聽聽 }
聽聽聽 聽聽聽
聽聽聽 聽聽聽 search.close();
聽聽聽 聽聽聽 directory.close();
聽聽聽 聽聽聽
聽聽聽 }
聽聽聽
}

]]>
主站蜘蛛池模板:
宝清县|
定西市|
金沙县|
铜川市|
左贡县|
共和县|
甘孜县|
调兵山市|
双柏县|
双城市|
邳州市|
措勤县|
丹寨县|
中西区|
长岭县|
南昌市|
磐安县|
金门县|
尉氏县|
孟州市|
芦山县|
县级市|
景宁|
烟台市|
阿克|
二手房|
仲巴县|
昂仁县|
库伦旗|
银川市|
珠海市|
大同市|
天峻县|
高唐县|
牡丹江市|
泾源县|
隆德县|
阜平县|
三门峡市|
泽普县|
岳西县|