首页 > Web开发 > 详细

Lucene开发详解(二)

时间:2015-03-25 21:45:59      阅读:286      评论:0      收藏:0      [点我收藏+]

吃了个饭回来,觉得Lucene有些知识点用法还没讲到,在这里补充一下:

一.Lucene的增删查改

/**
     * 增删查改
     * 
     * @throws Exception
     */
    public static void insert() throws Exception {
        String text5 = "hello,goodbye,man,woman";
        Date date1 = new Date();
        analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
        directory = FSDirectory.open(new File(INDEX_DIR));

        IndexWriterConfig config = new IndexWriterConfig(
                Version.LUCENE_CURRENT, analyzer);
        indexWriter = new IndexWriter(directory, config);
<span style="white-space:pre">	</span>
//增加索引
        /*Document doc1 = new Document();
        doc1.add(new TextField("filename", "text5", Store.YES));
        doc1.add(new TextField("content", text5, Store.YES));
        indexWriter.addDocument(doc1);
        indexWriter.commit();
        indexWriter.close();
<span style="white-space:pre">	</span>*/
<span style="white-space:pre">	</span>
//删除索引
<span style="white-space:pre">	</span>/*
<span style="white-space:pre">	indexWriter.deleteDocuments(new Term("filename",str));  
	indexWriter.close();</span>
<span style="white-space:pre">	</span>*/
<span style="white-space:pre">	</span>
//更新索引
        Date date2 = new Date();
        System.out.println("增加索引耗时:" + (date2.getTime() - date1.getTime()) + "ms\n");
    }
二.Lucene评分机制

技术分享

如图为公式,可以通过Document的setBoost方法来改变一下文档的boost因子进而修改分值。



Lucene开发详解(二)

原文:http://blog.csdn.net/wws199304/article/details/44625001

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!