<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的使用,希望今后能有所收獲,呵呵。。.現(xiàn)在寫的這個例子,是參考官方文檔寫的,寫這些東西只是為了自己所走過的路,同時也非常希望得到各位兄弟的指點,讓小弟少走點彎路

    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???? // 創(chuàng)建索引文件
    ??? public void writerContent() throws CorruptIndexException, LockObtainFailedException, IOException{
    ??? ???? // IndexWriter的第三個參數(shù)為false時,則在已有的索引文件追加內(nèi)容
    ??? ??? 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?? // 搜索包含關(guān)鍵字key的內(nèi)容
    ??? 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(" 查詢結(jié)果 : "+ doc.get("content"));
    ??? ??? }
    ??? ???
    ??? ??? search.close();
    ??? ??? directory.close();
    ??? ???
    ??? }
    ???
    }

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

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


    網(wǎng)站導航:
     
    主站蜘蛛池模板: 亚洲中文字幕无码av| a级毛片免费完整视频| 亚洲国产人成中文幕一级二级| 9i9精品国产免费久久| 亚洲中文久久精品无码1 | 亚洲中文字幕无码一久久区| 国产白丝无码免费视频| 亚洲日韩看片无码电影| 中文字幕不卡亚洲| 麻豆国产精品入口免费观看| 免费精品久久天干天干| 人人狠狠综合久久亚洲| 亚洲无线电影官网| 亚洲国产精品丝袜在线观看| 777成影片免费观看| 一区二区免费国产在线观看| 亚洲国产精品免费在线观看| 怡红院亚洲怡红院首页| 免费看国产成年无码AV片| 久久久国产精品福利免费| 亚洲hairy多毛pics大全| 亚洲视频精品在线| 亚洲一区二区三区国产精品| 中文字幕无码成人免费视频| 国产无遮挡裸体免费视频在线观看| 亚洲国产高清国产拍精品| 久久精品国产亚洲AV高清热| 精品国产亚洲男女在线线电影 | 日本免费一区尤物| 国产福利视精品永久免费| 成人A毛片免费观看网站| 激情无码亚洲一区二区三区| 亚洲高清免费在线观看| 亚洲永久精品ww47| 免费人成年激情视频在线观看| 最新免费jlzzjlzz在线播放| 麻豆成人久久精品二区三区免费| WWW国产成人免费观看视频| 久久精品国产亚洲av天美18| 国产成人精品亚洲日本在线| 亚洲欧洲日本天天堂在线观看|