【问题标题】:Lucene (6.2.1) deleteDocuments based on StoredFieldLucene(6.2.1)基于StoredField的deleteDocuments
【发布时间】:2017-10-28 23:33:03
【问题描述】:

我在索引中使用了少数StoredFieldTextField (Lucene 6.2.1)

对于每个文档,我都有自己的唯一 ID

如果我将字段创建为

 Field docID = new TextField("docID", docId, Field.Store.YES);

我可以像下面这样删除文档

Field transactionIdField = new TextField("transactionId", transactionId, Field.Store.YES);      
Term docIdTerm = new Term("docID", docId);
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
IndexWriter writer = repositoryWriters.getTargetIndexWriter(repositoryUuid);

// 4. remove document with docId
writer.deleteDocuments(docIdTerm);
LOG.log(Level.INFO, "Document removed from Index, docID: {0}", docId);
writer.commit();

但是如果我将字段创建为

 Field docID = new SttoredField("docID", docId);

文档没有被删除

如何根据存储的字段值删除文档?

我想将其保留为 StoredField,以便用户无法根据 docID 搜索文档

【问题讨论】:

    标签: search indexing lucene full-text-search


    【解决方案1】:

    引用StoredField 文档,

    一个字段,其值被存储以便 IndexSearcher.doc 和 IndexReader.document() 将返回该字段及其值。

    即它只是一个文档的存储字段,并且该字段没有术语或索引。

    方法,IndexWriter.deleteDocuments(Term...terms) 不会找到该文档,因为没有 StoredField 的术语。

    另一方面,TextField 被索引并为其生成术语,

    一个被索引和标记的字段,没有术语向量。为了 例如,这将用于包含大容量的“body”字段 文档的文本。

    已存储的TextField 已被索引和存储,因此术语可用并且值也被存储以重新构建文档。

    因此,在 sumamry 中,您不能仅基于 StoredField 删除文档,您还需要一个索引字段 - 具有相同名称才能删除它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 2021-11-11
      • 1970-01-01
      相关资源
      最近更新 更多