当前位置: 首页>>代码示例>>Java>>正文


Java IndexWriter.deleteDocuments方法代码示例

本文整理汇总了Java中org.apache.lucene.index.IndexWriter.deleteDocuments方法的典型用法代码示例。如果您正苦于以下问题:Java IndexWriter.deleteDocuments方法的具体用法?Java IndexWriter.deleteDocuments怎么用?Java IndexWriter.deleteDocuments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.index.IndexWriter的用法示例。


在下文中一共展示了IndexWriter.deleteDocuments方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteDocumentByTypeAndId

import org.apache.lucene.index.IndexWriter; //导入方法依赖的package包/类
private void deleteDocumentByTypeAndId(FeatureType type, Long id, IndexWriter writer) throws IOException {
    BooleanQuery.Builder deleteQueryBuilder = new BooleanQuery.Builder();
    TermQuery idQuery = new TermQuery(new Term(FeatureIndexFields.FILE_ID.getFieldName(),
                                               id.toString()));
    deleteQueryBuilder.add(idQuery, BooleanClause.Occur.MUST);

    if (type != FeatureType.GENE) {
        TermQuery typeQuery = new TermQuery(new Term(FeatureIndexFields.FEATURE_TYPE.getFieldName(),
                                                     type.getFileValue()));
        deleteQueryBuilder.add(typeQuery, BooleanClause.Occur.MUST);
    } else {
        deleteQueryBuilder.add(new TermQuery(new Term(FeatureIndexFields.FEATURE_TYPE.getFieldName(),
                                              FeatureType.BOOKMARK.getFileValue())), BooleanClause.Occur.MUST_NOT);
        deleteQueryBuilder.add(new TermQuery(new Term(FeatureIndexFields.FEATURE_TYPE.getFieldName(),
                                            FeatureType.VARIATION.getFileValue())), BooleanClause.Occur.MUST_NOT);
    }

    writer.deleteDocuments(deleteQueryBuilder.build());
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:20,代码来源:FeatureIndexDao.java

示例2: store

import org.apache.lucene.index.IndexWriter; //导入方法依赖的package包/类
@Override
public <S, T> void store(Collection<T> toAdd, Collection<S> toDelete, Convertor<? super T, ? extends Document> docConvertor, Convertor<? super S, ? extends Query> queryConvertor, boolean optimize) throws IOException {
    lock.writeLock().lock();
    try {
        final IndexWriter out = getWriter();
        try {
            for (S td : toDelete) {
                out.deleteDocuments(queryConvertor.convert(td));
            }
            if (toAdd.isEmpty()) {
                return;
            }
            for (Iterator<T> it = toAdd.iterator(); it.hasNext();) {
                T entry = it.next();
                it.remove();
                final Document doc = docConvertor.convert(entry);
                out.addDocument(doc);
            }
        } finally {

            try {
                out.close();
            } finally {
                refreshReader();
            }
        }
    } finally {
        lock.writeLock().unlock();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:MemoryIndex.java

示例3: testCoreCacheKey

import org.apache.lucene.index.IndexWriter; //导入方法依赖的package包/类
/** Test that core cache key (needed for NRT) is working */
public void testCoreCacheKey() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = new IndexWriterConfig(null);
    iwc.setMaxBufferedDocs(100);
    iwc.setMergePolicy(NoMergePolicy.INSTANCE);
    IndexWriter iw = new IndexWriter(dir, iwc);
    
    // add two docs, id:0 and id:1
    Document doc = new Document();
    Field idField = new StringField("id", "", Field.Store.NO);
    doc.add(idField);
    idField.setStringValue("0");
    iw.addDocument(doc);
    idField.setStringValue("1");
    iw.addDocument(doc);
    
    // open reader
    ShardId shardId = new ShardId("fake", "_na_", 1);
    DirectoryReader ir = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(iw), shardId);
    assertEquals(2, ir.numDocs());
    assertEquals(1, ir.leaves().size());

    // delete id:0 and reopen
    iw.deleteDocuments(new Term("id", "0"));
    DirectoryReader ir2 = DirectoryReader.openIfChanged(ir);
    
    // we should have the same cache key as before
    assertEquals(1, ir2.numDocs());
    assertEquals(1, ir2.leaves().size());
    assertSame(ir.leaves().get(0).reader().getCoreCacheKey(), ir2.leaves().get(0).reader().getCoreCacheKey());
    IOUtils.close(ir, ir2, iw, dir);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:34,代码来源:ESDirectoryReaderTests.java

示例4: deleteIndex

import org.apache.lucene.index.IndexWriter; //导入方法依赖的package包/类
/**
 * 删除指定博客的索引
 *
 * @param userid
 * @throws Exception
 */
public void deleteIndex(String userid) throws Exception {
  IndexWriter writer = getWriter();
  writer.deleteDocuments(new Term("userid", userid));

  writer.forceMergeDeletes(); // 强制删除
  writer.commit();
  writer.close();
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:15,代码来源:LuceneIndex.java

示例5: removeNote

import org.apache.lucene.index.IndexWriter; //导入方法依赖的package包/类
public void removeNote (Note note) throws IOException {
	
	Directory index = FSDirectory.open (Paths.get(indexDirectoryPath));
	
	Analyzer lowerCaseAnalyzer = new StandardAnalyzer ();
	
	IndexWriterConfig indexWriterConfig = new IndexWriterConfig (lowerCaseAnalyzer);
	
	indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
	
	IndexWriter indexWriter = new IndexWriter (index, indexWriterConfig);
	
	indexWriter.deleteDocuments(new Term ("id", note.getId()));
	
	indexWriter.commit();
	
	indexWriter.close();
	
	index.close();		
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:21,代码来源:NoteIndexer.java

示例6: removeEvent

import org.apache.lucene.index.IndexWriter; //导入方法依赖的package包/类
public void removeEvent (Event event) throws IOException {
	
	Directory index = FSDirectory.open (Paths.get(indexDirectoryPath));
	
	Analyzer lowerCaseAnalyzer = new StandardAnalyzer ();
	
	IndexWriterConfig indexWriterConfig = new IndexWriterConfig (lowerCaseAnalyzer);
	
	indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND);
	
	IndexWriter indexWriter = new IndexWriter (index, indexWriterConfig);
	
	indexWriter.deleteDocuments(new Term ("id", event.getId()));
	
	indexWriter.commit();
	
	indexWriter.close();
	
	index.close();		
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:21,代码来源:EventIndexer.java


注:本文中的org.apache.lucene.index.IndexWriter.deleteDocuments方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。