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

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

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

    隨筆-10  評(píng)論-66  文章-1  trackbacks-0
    ? 最近開(kāi)始搞下lucene,用空閑時(shí)間深入學(xué)習(xí)lucene的使用,希望今后能有所收獲,呵呵。。.現(xiàn)在寫的這個(gè)例子,是參考官方文檔寫的,寫這些東西只是為了自己所走過(guò)的路,同時(shí)也非常希望得到各位兄弟的指點(diǎn),讓小弟少走點(diǎ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的第三個(gè)參數(shù)為false時(shí),則在已有的索引文件追加內(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 閱讀(873) 評(píng)論(0)  編輯  收藏 所屬分類: lucene

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 日韩免费高清一级毛片在线| 无码国产精品一区二区免费式芒果| 日韩免费精品视频| 久久久亚洲欧洲日产国码是AV| av永久免费网站在线观看| 亚洲欧洲日产国码av系列天堂| aa毛片免费全部播放完整| 国产a v无码专区亚洲av| EEUSS影院WWW在线观看免费| 国产亚洲精品线观看动态图| 国产成人无码免费网站| 久久久久久久综合日本亚洲| 久久九九全国免费| 亚洲精品国产成人| 成年轻人网站色免费看| 精品久久久久亚洲| 亚洲人成影院在线无码观看| 免费国产在线视频| 亚洲精品乱码久久久久久下载| 黄页免费的网站勿入免费直接进入| 在线精品亚洲一区二区| 免费国产综合视频在线看| aa午夜免费剧场| 亚洲黄色在线网站| 青青草国产免费久久久下载| 一二三区免费视频| 99久久亚洲精品无码毛片| 女人18毛片a级毛片免费视频| 性生大片视频免费观看一级| 亚洲第一AV网站| 岛国av无码免费无禁网站| 特级毛片免费播放| 亚洲一区二区三区夜色| 免费的一级黄色片| a级毛片在线免费看| 亚洲男人天堂2018av| 亚洲欧洲无码AV电影在线观看| 亚洲国产精品免费在线观看| 精品国产亚洲AV麻豆| 2022年亚洲午夜一区二区福利 | 亚洲三级在线免费观看|