简体   繁体   English

IndexWriter deleteDocuments功能不起作用

[英]IndexWriter deleteDocuments function is not working

public void index(IndexItem indexItem) throws IOException {
    writer.deleteDocuments(new Term(IndexItem.ID,indexItem.getId().toString()));                    
    Document doc = new Document();
    // doc.add(new LongField(IndexItem.ID, indexItem.getId(), Field.Store.YES));
    doc.add(new TextField(IndexItem.CONTENT, indexItem.getContent(), Field.Store.NO));
    doc.add(new StringField(IndexItem.PATH, indexItem.getPath(), Field.Store.YES));

    // add the document to the index
    writer.addDocument(doc, analyzer);


    writer.updateDocument(new Term(IndexItem.CONTENT, indexItem.getContent().toString()), doc);
    System.out.println(indexItem.getTitle()); 
    writer.close();
}

Here Writer.deleteDocuments is not working. 这里Writer.deleteDocuments无法正常工作。 Thus each time I index a file, it doest not deletes already existing file then create a new one rather it just makes a copy of it. 因此,每次我索引一个文件时,它都不会删除现有文件,而是创建一个新文件,而只是制作一个副本。

Is this anything have to do with work.lock file 这与work.lock文件有关吗

You appear to have commented out the line that adds the IndexItem.ID field to the document. 您似乎已注释掉将IndexItem.ID字段添加到文档的行。 If that field isn't added to the document, then the call to deleteDocuments won't find any matches on that field, and nothing will be deleted. 如果该字段未添加到文档中,则对deleteDocuments的调用将在该字段上找不到任何匹配项,并且不会删除任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 随机函数在JavaScript中不起作用 - Random function not working in JavaScript CodeIgniter htaccess:`[controller] / [function] / [argument]`不起作用 - CodeIgniter htaccess: `[controller]/[function]/[argument]` not working Python删除功能在Apache中不起作用 - python delete function not working in apache register_shutdown_function()不起作用 - register_shutdown_function() not working file_get_contents / curl PHP函数不适用于IP地址 - file_get_contents/curl PHP Function Not Working For IP Address constantLine函数在石墨(0.9.12)和Django 1.6.1中不起作用 - constantLine function not working in graphite (0.9.12) and django 1.6.1 如果条件不起作用,则在Apache POI(版本3.15)中使用sumproduct函数 - sumproduct function in apache poi (version 3.15) with if condition is not working 大文件下载通过php函数readfile无法正常工作 - Big files download through php function readfile not working 除了 url() 之外,每个速度工具都可以逃脱 function 吗? - Every velocity tool escape function working except url()? 当PHP中的shell_exec()执行脚本时,Python open()函数不起作用 - Python open() function not working when script executed by shell_exec() in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM