<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-10  評論-66  文章-1  trackbacks-0
    ? 最近開始搞下lucene,用空閑時間深入學習lucene的使用,希望今后能有所收獲,呵呵。。.現在寫的這個例子,是參考官方文檔寫的,寫這些東西只是為了自己所走過的路,同時也非常希望得到各位兄弟的指點,讓小弟少走點彎路

    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的第三個參數為false時,則在已有的索引文件追加內容
    ??? ??? 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?? // 搜索包含關鍵字key的內容
    ??? 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();
    ??? ???
    ??? }
    ???
    }

    posted on 2008-01-21 21:02 javadragon 閱讀(873) 評論(0)  編輯  收藏 所屬分類: lucene

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 日韩大片在线永久免费观看网站| 4480yy私人影院亚洲| 久久精品亚洲AV久久久无码| 日韩内射激情视频在线播放免费| 亚洲伊人久久大香线蕉综合图片| 无码AV动漫精品一区二区免费| 无码不卡亚洲成?人片| 亚洲aⅴ无码专区在线观看| 天天拍拍天天爽免费视频| 国产亚洲玖玖玖在线观看| 亚洲第一成年免费网站| 亚洲日韩国产二区无码| 在线观看亚洲免费视频| 亚洲色大网站WWW永久网站| 成人福利免费视频| 亚洲午夜无码久久久久小说 | 亚洲午夜精品一级在线播放放| 美女视频黄a视频全免费网站色| 免费大香伊蕉在人线国产| 一级女性全黄久久生活片免费| 国产成人精品日本亚洲专区 | 又大又粗又爽a级毛片免费看| 国产精品亚洲片在线花蝴蝶| 亚洲av无码乱码在线观看野外| 国产亚洲精品资源在线26u| 九九精品成人免费国产片| 久久久亚洲AV波多野结衣| 中文字幕av无码无卡免费| 激情小说亚洲图片| 亚洲精品高清无码视频| 啦啦啦完整版免费视频在线观看| 国产婷婷综合丁香亚洲欧洲| 亚洲av无码专区在线观看素人| 国产做国产爱免费视频| 亚洲国产精品xo在线观看| 国产精品嫩草影院免费| 国产猛男猛女超爽免费视频| 亚洲av乱码一区二区三区香蕉| 免费乱码中文字幕网站| 99视频在线精品免费| 亚洲AV无码一区二区一二区|