Lucene开发详解(二)

吃了个饭回来,觉得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)