Search in sources :

Example 1 with SolrContentStore

use of org.alfresco.solr.content.SolrContentStore in project SearchServices by Alfresco.

the class SolrCoreLoadRegistration method registerForCore.

/**
 * Registers with the admin handler the information server and the trackers.
 */
public static void registerForCore(AlfrescoCoreAdminHandler adminHandler, CoreContainer coreContainer, SolrCore core, String coreName) {
    TrackerRegistry trackerRegistry = adminHandler.getTrackerRegistry();
    Properties props = new CoreDescriptorDecorator(core.getCoreDescriptor()).getProperties();
    if (Boolean.parseBoolean(props.getProperty("enable.alfresco.tracking", "false"))) {
        SolrTrackerScheduler scheduler = adminHandler.getScheduler();
        SolrResourceLoader loader = core.getLatestSchema().getResourceLoader();
        SolrKeyResourceLoader keyResourceLoader = new SolrKeyResourceLoader(loader);
        if (trackerRegistry.hasTrackersForCore(coreName)) {
            log.info("Trackers for " + coreName + " is already registered, shutting them down.");
            shutdownTrackers(coreName, trackerRegistry.getTrackersForCore(coreName), scheduler);
            trackerRegistry.removeTrackersForCore(coreName);
            adminHandler.getInformationServers().remove(coreName);
        }
        SOLRAPIClientFactory clientFactory = new SOLRAPIClientFactory();
        SOLRAPIClient repositoryClient = clientFactory.getSOLRAPIClient(props, keyResourceLoader, AlfrescoSolrDataModel.getInstance().getDictionaryService(CMISStrictDictionaryService.DEFAULT), AlfrescoSolrDataModel.getInstance().getNamespaceDAO());
        // Start content store
        SolrContentStore contentStore = new SolrContentStore(coreContainer.getSolrHome());
        SolrInformationServer srv = new SolrInformationServer(adminHandler, core, repositoryClient, contentStore);
        props.putAll(srv.getProps());
        adminHandler.getInformationServers().put(coreName, srv);
        log.info("Starting to track " + coreName);
        ModelTracker mTracker = null;
        // Prevents other threads from registering the ModelTracker at the same time
        synchronized (trackerRegistry) {
            mTracker = trackerRegistry.getModelTracker();
            if (mTracker == null) {
                log.debug("Creating ModelTracker when registering trackers for core " + coreName);
                mTracker = new ModelTracker(coreContainer.getSolrHome(), props, repositoryClient, coreName, srv);
                trackerRegistry.setModelTracker(mTracker);
                log.info("Ensuring first model sync.");
                mTracker.ensureFirstModelSync();
                log.info("Done ensuring first model sync.");
                // Scheduling the ModelTracker.
                scheduler.schedule(mTracker, coreName, props);
            }
        }
        List<Tracker> trackers = createTrackers(coreName, trackerRegistry, props, scheduler, repositoryClient, srv);
        CommitTracker commitTracker = new CommitTracker(props, repositoryClient, coreName, srv, trackers);
        trackerRegistry.register(coreName, commitTracker);
        scheduler.schedule(commitTracker, coreName, props);
        log.info("The Trackers are now scheduled to run");
        // Add the commitTracker to the list of scheduled trackers that can be shutdown
        trackers.add(commitTracker);
        core.addCloseHook(new CloseHook() {

            @Override
            public void preClose(SolrCore core) {
                log.info("Shutting down " + core.getName());
                SolrCoreLoadRegistration.shutdownTrackers(core.getName(), trackers, scheduler);
            }

            @Override
            public void postClose(SolrCore core) {
            }
        });
    }
}
Also used : ContentTracker(org.alfresco.solr.tracker.ContentTracker) Tracker(org.alfresco.solr.tracker.Tracker) MetadataTracker(org.alfresco.solr.tracker.MetadataTracker) CommitTracker(org.alfresco.solr.tracker.CommitTracker) CascadeTracker(org.alfresco.solr.tracker.CascadeTracker) AclTracker(org.alfresco.solr.tracker.AclTracker) ModelTracker(org.alfresco.solr.tracker.ModelTracker) SolrContentStore(org.alfresco.solr.content.SolrContentStore) SolrCore(org.apache.solr.core.SolrCore) CommitTracker(org.alfresco.solr.tracker.CommitTracker) Properties(java.util.Properties) TrackerRegistry(org.alfresco.solr.tracker.TrackerRegistry) SolrInformationServer(org.alfresco.solr.SolrInformationServer) ModelTracker(org.alfresco.solr.tracker.ModelTracker) CoreDescriptorDecorator(org.apache.solr.core.CoreDescriptorDecorator) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CloseHook(org.apache.solr.core.CloseHook) SOLRAPIClientFactory(org.alfresco.solr.client.SOLRAPIClientFactory) SOLRAPIClient(org.alfresco.solr.client.SOLRAPIClient) SolrTrackerScheduler(org.alfresco.solr.tracker.SolrTrackerScheduler) SolrKeyResourceLoader(org.alfresco.solr.SolrKeyResourceLoader)

Example 2 with SolrContentStore

use of org.alfresco.solr.content.SolrContentStore in project SearchServices by Alfresco.

the class FingerPrintComponent method process.

public void process(ResponseBuilder responseBuilder) throws IOException {
    if (!responseBuilder.req.getParams().getBool(FingerPrintComponent.COMPONENT_NAME, false)) {
        return;
    }
    SolrContentStore solrContentStore = getContentStore(responseBuilder.req);
    NamedList response = responseBuilder.rsp.getValues();
    String id = responseBuilder.req.getParams().get("id");
    long dbid = fetchDBID(id, responseBuilder.req.getSearcher());
    if (dbid == -1 && isNumber(id)) {
        dbid = Long.parseLong(id);
    }
    NamedList fingerPrint = new NamedList();
    if (dbid > -1) {
        SolrInputDocument solrDoc = solrContentStore.retrieveDocFromSolrContentStore(AlfrescoSolrDataModel.getTenantId(TenantService.DEFAULT_DOMAIN), dbid);
        if (solrDoc != null) {
            SolrInputField mh = solrDoc.getField("MINHASH");
            if (mh != null) {
                Collection col = mh.getValues();
                List l = new ArrayList();
                l.addAll(col);
                fingerPrint.add("MINHASH", l);
            }
        }
    }
    response.add("fingerprint", fingerPrint);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrContentStore(org.alfresco.solr.content.SolrContentStore) NamedList(org.apache.solr.common.util.NamedList) SolrInputField(org.apache.solr.common.SolrInputField) NamedList(org.apache.solr.common.util.NamedList)

Example 3 with SolrContentStore

use of org.alfresco.solr.content.SolrContentStore in project SearchServices by Alfresco.

the class CachedDocTransformer method transform.

/* (non-Javadoc)
     * @see org.apache.solr.response.transform.DocTransformer#transform(org.apache.solr.common.SolrDocument, int)
     */
@Override
public void transform(SolrDocument doc, int docid, float score) throws IOException {
    SolrInputDocument cachedDoc = null;
    try {
        String id = getFieldValueString(doc, FIELD_SOLR4_ID);
        TenantAclIdDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(id);
        CoreContainer coreContainer = context.getSearcher().getCore().getCoreContainer();
        AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler();
        SolrInformationServer srv = (SolrInformationServer) coreAdminHandler.getInformationServers().get(context.getSearcher().getCore().getName());
        SolrContentStore solrContentStore = srv.getSolrContentStore();
        cachedDoc = solrContentStore.retrieveDocFromSolrContentStore(tenantAndDbId.tenant, tenantAndDbId.dbId);
    } catch (StringIndexOutOfBoundsException e) {
    // ignore invalid forms ....
    }
    if (cachedDoc != null) {
        Collection<String> fieldNames = cachedDoc.getFieldNames();
        for (String fieldName : fieldNames) {
            SchemaField schemaField = context.getSearcher().getSchema().getFieldOrNull(fieldName);
            if (schemaField != null) {
                doc.removeFields(fieldName);
                if (schemaField.multiValued()) {
                    int index = fieldName.lastIndexOf("@{");
                    if (index == -1) {
                        doc.addField(fieldName, cachedDoc.getFieldValues(fieldName));
                    } else {
                        String alfrescoFieldName = AlfrescoSolrDataModel.getInstance().getAlfrescoPropertyFromSchemaField(fieldName);
                        Collection<Object> values = cachedDoc.getFieldValues(fieldName);
                        ArrayList<Object> newValues = new ArrayList<Object>(values.size());
                        for (Object value : values) {
                            if (value instanceof String) {
                                String stringValue = (String) value;
                                int start = stringValue.lastIndexOf('\u0000');
                                if (start == -1) {
                                    newValues.add(stringValue);
                                } else {
                                    newValues.add(stringValue.substring(start + 1));
                                }
                            } else {
                                newValues.add(value);
                            }
                        }
                        doc.removeFields(alfrescoFieldName);
                        doc.addField(alfrescoFieldName, newValues);
                    }
                } else {
                    int index = fieldName.lastIndexOf("@{");
                    if (index == -1) {
                        doc.addField(fieldName, cachedDoc.getFieldValue(fieldName));
                    } else {
                        String alfrescoFieldName = AlfrescoSolrDataModel.getInstance().getAlfrescoPropertyFromSchemaField(fieldName);
                        alfrescoFieldName = alfrescoFieldName.contains(":") ? alfrescoFieldName.replace(":", "_") : alfrescoFieldName;
                        Object value = cachedDoc.getFieldValue(fieldName);
                        if (value instanceof String) {
                            String stringValue = (String) value;
                            int start = stringValue.lastIndexOf('\u0000');
                            if (start == -1) {
                                doc.removeFields(alfrescoFieldName);
                                doc.addField(alfrescoFieldName, stringValue);
                            } else {
                                doc.removeFields(alfrescoFieldName);
                                doc.addField(alfrescoFieldName, stringValue.substring(start + 1));
                            }
                        } else {
                            doc.removeFields(alfrescoFieldName);
                            doc.addField(alfrescoFieldName, value);
                        }
                    }
                }
            }
        }
    }
}
Also used : TenantAclIdDbId(org.alfresco.solr.AlfrescoSolrDataModel.TenantAclIdDbId) SolrContentStore(org.alfresco.solr.content.SolrContentStore) ArrayList(java.util.ArrayList) SolrInformationServer(org.alfresco.solr.SolrInformationServer) SchemaField(org.apache.solr.schema.SchemaField) SolrInputDocument(org.apache.solr.common.SolrInputDocument) CoreContainer(org.apache.solr.core.CoreContainer) AlfrescoCoreAdminHandler(org.alfresco.solr.AlfrescoCoreAdminHandler)

Example 4 with SolrContentStore

use of org.alfresco.solr.content.SolrContentStore in project SearchServices by Alfresco.

the class AlfrescoSolrHighlighter method getDocument.

private Document getDocument(Document doc, SolrQueryRequest req) throws IOException {
    try {
        String id = getFieldValueString(doc, FIELD_SOLR4_ID);
        TenantAclIdDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(id);
        CoreContainer coreContainer = req.getSearcher().getCore().getCoreContainer();
        AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler();
        SolrInformationServer srv = (SolrInformationServer) coreAdminHandler.getInformationServers().get(req.getSearcher().getCore().getName());
        SolrContentStore solrContentStore = srv.getSolrContentStore();
        SolrInputDocument sid = solrContentStore.retrieveDocFromSolrContentStore(tenantAndDbId.tenant, tenantAndDbId.dbId);
        if (sid == null) {
            sid = new SolrInputDocument();
            sid.addField(FIELD_SOLR4_ID, id);
            sid.addField("_version_", 0);
            return DocumentBuilder.toDocument(sid, req.getSchema());
        } else {
            sid.removeField(FIELD_SOLR4_ID);
            sid.addField(FIELD_SOLR4_ID, id);
            return DocumentBuilder.toDocument(sid, req.getSchema());
        }
    } catch (StringIndexOutOfBoundsException e) {
        throw new IOException(e);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) TenantAclIdDbId(org.alfresco.solr.AlfrescoSolrDataModel.TenantAclIdDbId) CoreContainer(org.apache.solr.core.CoreContainer) AlfrescoCoreAdminHandler(org.alfresco.solr.AlfrescoCoreAdminHandler) SolrContentStore(org.alfresco.solr.content.SolrContentStore) IOException(java.io.IOException) SolrInformationServer(org.alfresco.solr.SolrInformationServer)

Example 5 with SolrContentStore

use of org.alfresco.solr.content.SolrContentStore in project SearchServices by Alfresco.

the class AlfrescoSolrClusteringComponent method getSolrInputDocument.

private SolrInputDocument getSolrInputDocument(Document doc, SolrQueryRequest req) throws IOException {
    try {
        String id = getFieldValueString(doc, FIELD_SOLR4_ID);
        TenantAclIdDbId tenantAndDbId = AlfrescoSolrDataModel.decodeNodeDocumentId(id);
        CoreContainer coreContainer = req.getSearcher().getCore().getCoreContainer();
        AlfrescoCoreAdminHandler coreAdminHandler = (AlfrescoCoreAdminHandler) coreContainer.getMultiCoreHandler();
        SolrInformationServer srv = (SolrInformationServer) coreAdminHandler.getInformationServers().get(req.getSearcher().getCore().getName());
        SolrContentStore solrContentStore = srv.getSolrContentStore();
        SolrInputDocument sid = solrContentStore.retrieveDocFromSolrContentStore(tenantAndDbId.tenant, tenantAndDbId.dbId);
        return sid;
    } catch (StringIndexOutOfBoundsException e) {
        throw new IOException(e);
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) TenantAclIdDbId(org.alfresco.solr.AlfrescoSolrDataModel.TenantAclIdDbId) CoreContainer(org.apache.solr.core.CoreContainer) AlfrescoCoreAdminHandler(org.alfresco.solr.AlfrescoCoreAdminHandler) SolrContentStore(org.alfresco.solr.content.SolrContentStore) IOException(java.io.IOException) SolrInformationServer(org.alfresco.solr.SolrInformationServer)

Aggregations

SolrContentStore (org.alfresco.solr.content.SolrContentStore)5 SolrInformationServer (org.alfresco.solr.SolrInformationServer)4 SolrInputDocument (org.apache.solr.common.SolrInputDocument)4 AlfrescoCoreAdminHandler (org.alfresco.solr.AlfrescoCoreAdminHandler)3 TenantAclIdDbId (org.alfresco.solr.AlfrescoSolrDataModel.TenantAclIdDbId)3 CoreContainer (org.apache.solr.core.CoreContainer)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 SolrKeyResourceLoader (org.alfresco.solr.SolrKeyResourceLoader)1 SOLRAPIClient (org.alfresco.solr.client.SOLRAPIClient)1 SOLRAPIClientFactory (org.alfresco.solr.client.SOLRAPIClientFactory)1 AclTracker (org.alfresco.solr.tracker.AclTracker)1 CascadeTracker (org.alfresco.solr.tracker.CascadeTracker)1 CommitTracker (org.alfresco.solr.tracker.CommitTracker)1 ContentTracker (org.alfresco.solr.tracker.ContentTracker)1 MetadataTracker (org.alfresco.solr.tracker.MetadataTracker)1 ModelTracker (org.alfresco.solr.tracker.ModelTracker)1 SolrTrackerScheduler (org.alfresco.solr.tracker.SolrTrackerScheduler)1 Tracker (org.alfresco.solr.tracker.Tracker)1