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

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

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

    laoding
    本來我以為,隱身了別人就找不到我,沒有用的,像我這樣拉風的男人,無論走到哪里,都像在黑暗中的螢火蟲一樣,那樣的鮮明,那樣的出眾。我那憂郁的眼神,稀疏的胡茬,那微微隆起的將軍肚和親切的笑容......都深深吸引了眾人......
    posts - 0,  comments - 37,  trackbacks - 0

    首先下載lucene相關jar包,這里就不多說,自己網上找

    在eclipse下建立web工程luceneTest

    將jar包加載到你的web工程里面

    新建類Index.java,代碼如下:


    import java.io.IOException;
    import org.apache.lucene.analysis.Analyzer;
    import org.apache.lucene.analysis.SimpleAnalyzer;
    import org.apache.lucene.analysis.standard.StandardAnalyzer;
    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.store.Directory;
    import org.apache.lucene.store.FSDirectory;
    import org.apache.lucene.store.LockObtainFailedException;
    import org.apache.lucene.store.RAMDirectory;

    /*
     * Create Date:2007-10-26 下午02:52:53
     *
     * Author:dingkm
     *
     * Version: V1.0
     *
     * Description:對進行修改的功能進行描述
     *
     *
     */

    public class Index {

     /**
      * @Description 方法實現功能描述
      * @param args
      *            void
      * @throws 拋出異常說明
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
      try {
       new Index().index();
       System.out.println("create index success!!!");
      } catch (CorruptIndexException e) {
       e.printStackTrace();
      } catch (LockObtainFailedException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
     }

     public void index() throws CorruptIndexException, LockObtainFailedException, IOException{
       long start = System.currentTimeMillis();
      
      // 建立索引的路徑
         String path = "c:\\index2";
      Document doc1 = new Document();  
            doc1.add( new Field("name", "中華人民共和國",Field.Store.YES,Field.Index.TOKENIZED));  
            doc1.add( new Field("content", "標題或正文包括",Field.Store.YES,Field.Index.TOKENIZED)); 
            doc1.add( new Field("time", "20080715",Field.Store.YES,Field.Index.TOKENIZED));
            Document doc2 = new Document();  
            doc2.add(new Field("name", "大中國中國",Field.Store.YES,Field.Index.TOKENIZED));  
            IndexWriter writer = new IndexWriter(FSDirectory.getDirectory(path, true), new StandardAnalyzer(), true);
            writer.setMaxMergeDocs(10);
            writer.setMaxFieldLength(3);  
            writer.addDocument(doc1);  
            writer.setMaxFieldLength(3);  
            writer.addDocument(doc2);  
            writer.close();  
     
     
          
            System.out.println("=========================");
            System.out.print(System.currentTimeMillis() - start);
      System.out.println("total milliseconds");
      System.out.println("=========================");
           

     }

    }



    執行這個類,可以看到結果:

    =========================
    375total milliseconds
    =========================
    create index success!!!

    可以看到索引創建成功。


    下面我們來創建搜索類,Search.java

    import java.io.IOException;

    import org.apache.lucene.analysis.standard.StandardAnalyzer;
    import org.apache.lucene.document.Document;
    import org.apache.lucene.index.CorruptIndexException;
    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;

    /*
     * Create Date:2007-10-26 下午02:56:12
     *
     * Author:dingkm
     *
     * Version: V1.0
     *
     * Description:對進行修改的功能進行描述
     *
     * 
     */

    public class Search {

     /** 
      *   @Description 方法實現功能描述 
      *   @param args
      *   void
      *   @throws  拋出異常說明
      */
     public static void main(String[] args) {
      // TODO Auto-generated method stub
       String path = "c:\\index2";
       try {
       new Search().search(path);
      } catch (CorruptIndexException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (ParseException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }

     }
     
     
     public void search(String path) throws CorruptIndexException, IOException, ParseException{
       IndexSearcher searcher = new IndexSearcher(path);  
             Hits hits = null;  
             Query query = null;  
             QueryParser qp = new QueryParser("name",new StandardAnalyzer());  

                query = qp.parse("中");
             hits = searcher.search(query); 
                java.text.NumberFormat   format   =   java.text.NumberFormat.getNumberInstance();  
             System.out.println("查找到共" + hits.length() + "個結果");  
                for   (int   i   =   0;   i   <   hits.length();   i++)   {  
                      //開始輸出查詢結果  
                      Document   doc   =   hits.doc(i);  
                      System.out.println(doc.get("name"));  
                      System.out.println("content="+doc.get("content"));
                      System.out.println("time="+doc.get("time"));
                      System.out.println("準確度為:"   +   format.format(hits.score(i)   *   100.0)   +   "%");  
    //                  System.out.println(doc.get("CONTENT"));  
                  } 
         
     }

    }


    執行它,會得到以下結果:

    查找到共2個結果
    中華人民共和國
    content=標題或正文包括
    time=20080715
    準確度為:29.727%
    大中國中國
    content=null
    time=null
    準確度為:29.727%


    這樣就完成了我們的程序

    這是我第一次發表文章
    說的比較簡單,可能很多地方說的不清楚
    希望大家多多支持

    有什么不明白的歡迎留言。

    posted on 2008-09-04 13:06 老丁 閱讀(538) 評論(0)  編輯  收藏 所屬分類: 搜索引擎 lucene
    本博客主為學習和復習之用,無關其他,想罵人的繞道
    Email:dkm123456@126.com
    大家一起交流進步
    QQ:283582761


    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    留言簿(4)

    我參與的團隊

    文章分類(50)

    文章檔案(48)

    相冊

    朋友

    搜索

    •  

    積分與排名

    • 積分 - 96478
    • 排名 - 600

    最新評論

    主站蜘蛛池模板: 亚洲综合图片小说区热久久| 亚洲色大成网站WWW久久九九| 中文字幕亚洲精品| 久久久久免费看黄a级试看| 亚洲午夜福利717| 久久国产一片免费观看| 国产成人亚洲精品91专区手机| 瑟瑟网站免费网站入口| 亚洲精品无码久久不卡| 99视频在线免费观看| 亚洲AV无码精品色午夜果冻不卡| 久久国产免费观看精品| 亚洲国产成人久久精品影视| 午夜视频在线免费观看| 亚洲色av性色在线观无码| 在线视频免费观看爽爽爽| 亚洲AV无码精品蜜桃| 国产乱弄免费视频| 一级毛片免费播放男男| 国产精品国产亚洲精品看不卡| 日韩在线永久免费播放| 国产亚洲sss在线播放| 免费萌白酱国产一区二区| 黄 色一级 成 人网站免费| 久久亚洲精品AB无码播放| 又粗又大又黑又长的免费视频| 亚洲日韩av无码中文| 亚洲日本中文字幕一区二区三区 | 亚洲一区免费在线观看| 亚洲中文字幕久久精品无码VA| 国产免费爽爽视频免费可以看| 成人免费ā片在线观看| 亚洲明星合成图综合区在线| 日韩一级免费视频| 三级网站免费观看| 国产午夜亚洲精品| 亚洲乱码精品久久久久..| 91香蕉视频免费| 福利免费在线观看| 亚洲最大天堂无码精品区| 亚洲男女内射在线播放|