use of com.helger.pd.indexer.lucene.AllDocumentsCollector in project phoss-directory by phax.
the class PDStorageManager method getAllContainedParticipantIDs.
@Nonnull
@ReturnsMutableCopy
public ICommonsSortedMap<IParticipantIdentifier, MutableInt> getAllContainedParticipantIDs(@Nonnull final EQueryMode eQueryMode) {
// Map from ID to entity count
final ICommonsSortedMap<IParticipantIdentifier, MutableInt> aTargetSet = new CommonsTreeMap<>();
final Query aQuery = eQueryMode.getEffectiveQuery(new MatchAllDocsQuery());
try {
final ObjIntConsumer<Document> aConsumer = (aDoc, nDocID) -> {
final IParticipantIdentifier aResolvedParticipantID = PDField.PARTICIPANT_ID.getDocValue(aDoc);
aTargetSet.computeIfAbsent(aResolvedParticipantID, k -> new MutableInt(0)).inc();
};
final Collector aCollector = new AllDocumentsCollector(m_aLucene, aConsumer);
searchAtomic(aQuery, aCollector);
} catch (final IOException ex) {
LOGGER.error("Error searching for documents with query " + aQuery, ex);
}
return aTargetSet;
}
use of com.helger.pd.indexer.lucene.AllDocumentsCollector in project phoss-directory by phax.
the class PDStorageManager method searchAll.
public void searchAll(@Nonnull final Query aQuery, @CheckForSigned final int nMaxResultCount, @Nonnull final Consumer<Document> aConsumer) throws IOException {
ValueEnforcer.notNull(aQuery, "Query");
ValueEnforcer.notNull(aConsumer, "Consumer");
if (nMaxResultCount <= 0) {
// Search all
final ObjIntConsumer<Document> aConverter = (aDoc, nDocID) -> aConsumer.accept(aDoc);
final Collector aCollector = new AllDocumentsCollector(m_aLucene, aConverter);
searchAtomic(aQuery, aCollector);
} else {
// Search top docs only
// Lucene 8
// final TopScoreDocCollector aCollector = TopScoreDocCollector.create
// (nMaxResultCount, Integer.MAX_VALUE);
final TopScoreDocCollector aCollector = TopScoreDocCollector.create(nMaxResultCount);
searchAtomic(aQuery, aCollector);
for (final ScoreDoc aScoreDoc : aCollector.topDocs().scoreDocs) {
final Document aDoc = m_aLucene.getDocument(aScoreDoc.doc);
if (aDoc == null)
throw new IllegalStateException("Failed to resolve Lucene Document with ID " + aScoreDoc.doc);
// Pass to Consumer
aConsumer.accept(aDoc);
}
}
}
use of com.helger.pd.indexer.lucene.AllDocumentsCollector in project phoss-directory by phax.
the class PageSecureParticipantCount method fillContent.
@Override
protected void fillContent(@Nonnull final WebPageExecutionContext aWPEC) {
final IRequestWebScopeWithoutResponse aRequestScope = aWPEC.getRequestScope();
final HCNodeList aNodeList = aWPEC.getNodeList();
{
final BootstrapButtonToolbar aToolbar = new BootstrapButtonToolbar(aWPEC);
aToolbar.addButton("Refresh", aWPEC.getSelfHref(), EDefaultIcon.MAGNIFIER);
aToolbar.addButton("Delete deleted", AJAX_DELETE_DELETED.getInvocationURL(aRequestScope), EDefaultIcon.DELETE);
aNodeList.addChild(aToolbar);
}
final int nNotDeletedCount = PDMetaManager.getStorageMgr().getContainedParticipantCount(EQueryMode.NON_DELETED_ONLY);
aNodeList.addChild(h3(nNotDeletedCount + " participants (entities) are contained"));
final int nDeletedCount = PDMetaManager.getStorageMgr().getContainedParticipantCount(EQueryMode.DELETED_ONLY);
aNodeList.addChild(h3(nDeletedCount + " deleted participants (entities) are contained"));
final int nReIndexCount = PDMetaManager.getIndexerMgr().getReIndexList().getItemCount();
aNodeList.addChild(h3(nReIndexCount + " re-index items are contained"));
final int nDeadCount = PDMetaManager.getIndexerMgr().getDeadList().getItemCount();
aNodeList.addChild(h3(nDeadCount + " dead items are contained"));
if (false)
try {
final Collector aCollector = new AllDocumentsCollector(PDMetaManager.getLucene(), (aDoc, nIdx) -> {
final BootstrapTable aTable = new BootstrapTable();
for (final IndexableField f : aDoc.getFields()) aTable.addBodyRow().addCells(f.name(), f.fieldType().toString(), f.stringValue());
aNodeList.addChild(aTable);
aNodeList.addChild(new HCHR());
});
PDMetaManager.getStorageMgr().searchAtomic(new MatchAllDocsQuery(), aCollector);
} catch (final IOException ex) {
}
}
Aggregations