本文整理匯總了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();
}