Search in sources :

Example 1 with AllDocumentsCollector

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;
}
Also used : Query(org.apache.lucene.search.Query) ScoreDoc(org.apache.lucene.search.ScoreDoc) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) FieldType(org.apache.lucene.document.FieldType) LoggerFactory(org.slf4j.LoggerFactory) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) CollectionHelper(com.helger.commons.collection.CollectionHelper) CheckForSigned(javax.annotation.CheckForSigned) PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) Document(org.apache.lucene.document.Document) Locale(java.util.Locale) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) PDField(com.helger.pd.indexer.storage.field.PDField) CGlobal(com.helger.commons.CGlobal) Occur(org.apache.lucene.search.BooleanClause.Occur) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) IThrowingRunnable(com.helger.commons.callback.IThrowingRunnable) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) AuditHelper(com.helger.photon.audit.AuditHelper) PDName(com.helger.pd.businesscard.generic.PDName) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) IndexSearcher(org.apache.lucene.search.IndexSearcher) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) ESuccess(com.helger.commons.state.ESuccess) ObjIntConsumer(java.util.function.ObjIntConsumer) Function(java.util.function.Function) IThrowingSupplier(com.helger.commons.functional.IThrowingSupplier) PDLucene(com.helger.pd.indexer.lucene.PDLucene) IPDStorageManager(com.helger.pd.indexer.mgr.IPDStorageManager) Store(org.apache.lucene.document.Field.Store) ICommonsSortedMap(com.helger.commons.collection.impl.ICommonsSortedMap) IntPoint(org.apache.lucene.document.IntPoint) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) TopDocs(org.apache.lucene.search.TopDocs) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) MutableInt(com.helger.commons.mutable.MutableInt) StringHelper(com.helger.commons.string.StringHelper) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) Collector(org.apache.lucene.search.Collector) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) ValueEnforcer(com.helger.commons.ValueEnforcer) IMutableStatisticsHandlerKeyedTimer(com.helger.commons.statistics.IMutableStatisticsHandlerKeyedTimer) Consumer(java.util.function.Consumer) StatisticsManager(com.helger.commons.statistics.StatisticsManager) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Field(org.apache.lucene.document.Field) StopWatch(com.helger.commons.timing.StopWatch) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) TextField(org.apache.lucene.document.TextField) IndexOptions(org.apache.lucene.index.IndexOptions) Immutable(javax.annotation.concurrent.Immutable) PDContact(com.helger.pd.businesscard.generic.PDContact) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) MutableInt(com.helger.commons.mutable.MutableInt) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) Collector(org.apache.lucene.search.Collector) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) IOException(java.io.IOException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Document(org.apache.lucene.document.Document) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 2 with AllDocumentsCollector

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);
        }
    }
}
Also used : Query(org.apache.lucene.search.Query) ScoreDoc(org.apache.lucene.search.ScoreDoc) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) FieldType(org.apache.lucene.document.FieldType) LoggerFactory(org.slf4j.LoggerFactory) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) CollectionHelper(com.helger.commons.collection.CollectionHelper) CheckForSigned(javax.annotation.CheckForSigned) PDIdentifier(com.helger.pd.businesscard.generic.PDIdentifier) Document(org.apache.lucene.document.Document) Locale(java.util.Locale) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) PDField(com.helger.pd.indexer.storage.field.PDField) CGlobal(com.helger.commons.CGlobal) Occur(org.apache.lucene.search.BooleanClause.Occur) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) PDExtendedBusinessCard(com.helger.pd.indexer.businesscard.PDExtendedBusinessCard) IThrowingRunnable(com.helger.commons.callback.IThrowingRunnable) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) AuditHelper(com.helger.photon.audit.AuditHelper) PDName(com.helger.pd.businesscard.generic.PDName) ICommonsList(com.helger.commons.collection.impl.ICommonsList) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) IndexSearcher(org.apache.lucene.search.IndexSearcher) PDBusinessEntity(com.helger.pd.businesscard.generic.PDBusinessEntity) ESuccess(com.helger.commons.state.ESuccess) ObjIntConsumer(java.util.function.ObjIntConsumer) Function(java.util.function.Function) IThrowingSupplier(com.helger.commons.functional.IThrowingSupplier) PDLucene(com.helger.pd.indexer.lucene.PDLucene) IPDStorageManager(com.helger.pd.indexer.mgr.IPDStorageManager) Store(org.apache.lucene.document.Field.Store) ICommonsSortedMap(com.helger.commons.collection.impl.ICommonsSortedMap) IntPoint(org.apache.lucene.document.IntPoint) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) TopDocs(org.apache.lucene.search.TopDocs) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) MutableInt(com.helger.commons.mutable.MutableInt) StringHelper(com.helger.commons.string.StringHelper) PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) IOException(java.io.IOException) Collector(org.apache.lucene.search.Collector) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) ValueEnforcer(com.helger.commons.ValueEnforcer) IMutableStatisticsHandlerKeyedTimer(com.helger.commons.statistics.IMutableStatisticsHandlerKeyedTimer) Consumer(java.util.function.Consumer) StatisticsManager(com.helger.commons.statistics.StatisticsManager) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Field(org.apache.lucene.document.Field) StopWatch(com.helger.commons.timing.StopWatch) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) TextField(org.apache.lucene.document.TextField) IndexOptions(org.apache.lucene.index.IndexOptions) Immutable(javax.annotation.concurrent.Immutable) PDContact(com.helger.pd.businesscard.generic.PDContact) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) Collector(org.apache.lucene.search.Collector) TopScoreDocCollector(org.apache.lucene.search.TopScoreDocCollector) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) Document(org.apache.lucene.document.Document) ScoreDoc(org.apache.lucene.search.ScoreDoc)

Example 3 with AllDocumentsCollector

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) {
        }
}
Also used : IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) WebPageExecutionContext(com.helger.photon.uicore.page.WebPageExecutionContext) AbstractAppWebPage(com.helger.pd.publisher.ui.AbstractAppWebPage) EDefaultIcon(com.helger.photon.uicore.icon.EDefaultIcon) IndexableField(org.apache.lucene.index.IndexableField) PDMetaManager(com.helger.pd.indexer.mgr.PDMetaManager) IOException(java.io.IOException) Collector(org.apache.lucene.search.Collector) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) AjaxFunctionDeclaration(com.helger.photon.ajax.decl.AjaxFunctionDeclaration) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) EQueryMode(com.helger.pd.indexer.storage.EQueryMode) Nonempty(com.helger.commons.annotation.Nonempty) HCHR(com.helger.html.hc.html.grouping.HCHR) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) Nonnull(javax.annotation.Nonnull) HCNodeList(com.helger.html.hc.impl.HCNodeList) IndexableField(org.apache.lucene.index.IndexableField) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapTable(com.helger.photon.bootstrap4.table.BootstrapTable) HCHR(com.helger.html.hc.html.grouping.HCHR) Collector(org.apache.lucene.search.Collector) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) AllDocumentsCollector(com.helger.pd.indexer.lucene.AllDocumentsCollector) BootstrapButtonToolbar(com.helger.photon.bootstrap4.buttongroup.BootstrapButtonToolbar) IOException(java.io.IOException) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Aggregations

AllDocumentsCollector (com.helger.pd.indexer.lucene.AllDocumentsCollector)3 IOException (java.io.IOException)3 Nonnull (javax.annotation.Nonnull)3 CGlobal (com.helger.commons.CGlobal)2 ValueEnforcer (com.helger.commons.ValueEnforcer)2 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)2 IThrowingRunnable (com.helger.commons.callback.IThrowingRunnable)2 CollectionHelper (com.helger.commons.collection.CollectionHelper)2 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)2 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)2 CommonsTreeMap (com.helger.commons.collection.impl.CommonsTreeMap)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)2 ICommonsSortedMap (com.helger.commons.collection.impl.ICommonsSortedMap)2 PDTWebDateHelper (com.helger.commons.datetime.PDTWebDateHelper)2 IThrowingSupplier (com.helger.commons.functional.IThrowingSupplier)2 MutableInt (com.helger.commons.mutable.MutableInt)2 ESuccess (com.helger.commons.state.ESuccess)2 IMutableStatisticsHandlerKeyedTimer (com.helger.commons.statistics.IMutableStatisticsHandlerKeyedTimer)2 StatisticsManager (com.helger.commons.statistics.StatisticsManager)2