本文整理汇总了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());
}
示例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();
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}