public class SolrIndexer extends AbstractLogEnabled implements Component, Serviceable, Initializable, Contextualizable
Modifier and Type | Class and Description |
---|---|
(package private) class |
SolrIndexer.IndexationResult |
Modifier and Type | Field and Description |
---|---|
private static ThreadLocal<SimpleDateFormat> |
__DATE_FORMAT |
private static int |
__SOLR_STRING_NB_BYTES_LIMIT |
protected String |
_ametysInternalUrl
The Ametys internal URL used by Solr to query Ametys
|
private static String |
_CONFIGSET_NAME_PREFIX |
protected Context |
_context
The avalon context
|
private static List<String> |
_READ_ONLY_FIELDS |
private static List<String> |
_READ_ONLY_FIELDTYPES |
protected AmetysObjectResolver |
_resolver
The ametys object resolver.
|
protected SchemaDefinitionProviderExtensionPoint |
_schemaDefProviderEP
The schema definition provider extension point.
|
protected SchemaHelper |
_schemaHelper
The schema helper.
|
protected SolrClientProvider |
_solrClientProvider
The Solr client provider
|
protected SolrContentIndexer |
_solrContentIndexer
Solr Ametys contents indexer
|
protected String |
_solrCorePrefix
The solr core prefix.
|
protected SolrResourceIndexer |
_solrResourceIndexer
Solr resource indexer.
|
protected SolrWorkflowIndexer |
_solrWorkflowIndexer
Solr workflow indexer.
|
protected WorkspaceSelector |
_workspaceSelector
The workspace selector.
|
static String |
ROLE
The component role.
|
Constructor and Description |
---|
SolrIndexer() |
Modifier and Type | Method and Description |
---|---|
private void |
_createConfigset(String name) |
private SolrClient |
_defaultSolrClient() |
private void |
_doIndexContent(Content content,
String workspaceName,
boolean indexAttachments,
boolean commit) |
protected SolrClient |
_getSolrClient(String workspaceName)
Gets the Solr client
|
private void |
_indexContentAttachment(Resource resource,
SolrInputDocument document,
Content content) |
protected void |
_indexResourceDocument(Resource resource,
SolrInputDocument document)
Index a populated solr input document of type Resource.
|
protected void |
addCustomUpdates(List<org.apache.solr.client.solrj.request.schema.SchemaRequest.Update> updates,
SchemaFields schemaFields)
Compute the list of custom
SchemaRequest.Update directives. |
protected void |
addStaticSchemaUpdates(List<org.apache.solr.client.solrj.request.schema.SchemaRequest.Update> updates,
org.apache.solr.client.solrj.response.schema.SchemaRepresentation staticSchema,
SchemaFields schemaFields)
Compute the list of
SchemaRequest.Update directives from the static schema. |
protected void |
clearSchema(SolrClient solrClient,
String collection)
Delete all the fields of the existing schema in the given collection.
|
void |
commit()
Process a Solr commit operation in all workspaces.
|
void |
commit(String workspaceName)
Process a Solr commit operation in given workspace.
|
void |
contextualize(Context context) |
void |
createCore(String name)
Create a Solr core.
|
static SimpleDateFormat |
dateFormat()
Returns the formatter for indexing dates.
|
protected boolean |
definitionExists(SchemaDefinition definition,
SchemaFields schemaFields)
Test if the given schema definition exists in the given
SchemaFields reference. |
void |
deleteCore(String name)
Delete a Solr core.
|
protected void |
deleteRepeaterDocs(String contentId,
String workspaceName)
Delete repeater documents of a specified content.
|
protected void |
doIndexContent(Content content,
String workspaceName)
Add or update a content into Solr index
|
protected SolrIndexer.IndexationResult |
doIndexContents(Iterable<Content> contents,
String workspaceName,
boolean indexAttachments,
boolean commit)
Send some contents for indexation in the solr server.
|
protected void |
doIndexContentWorkflow(Content content,
String workspaceName,
boolean commit)
Index the whole workflow of a content.
|
protected void |
doIndexExplorerItem(AmetysObject node,
String documentType,
TraversableAmetysObject resourceRoot)
Add or update a resource into Solr index
|
protected void |
doIndexResource(Resource resource,
String documentType,
TraversableAmetysObject resourceRoot)
Add or update a resource into Solr index
|
protected SolrIndexer.IndexationResult |
doIndexResources(Iterable<? extends AmetysObject> resources,
String documentType,
TraversableAmetysObject resourceRoot,
String workspaceName,
boolean commit)
Send some resources for indexation in the solr server.
|
protected void |
doUnindexContentAttachments(String contentId,
String workspaceName)
Delete content attachments documents of a given content from the Solr server.
|
protected void |
doUnindexDocument(String id,
String workspaceName)
Delete a document from the Solr server.
|
Set<String> |
getCoreNames()
Get the names of the Solr cores.
|
protected Set<String> |
getRealCoreNames()
Get the names of the Solr cores.
|
protected org.apache.solr.client.solrj.request.schema.SchemaRequest.Update |
getSchemaUpdate(SchemaDefinition definition)
Get the schema
SchemaRequest.Update directive from the given schema definition. |
Map<String,Object> |
indexAllContents(String workspaceName,
boolean indexAttachments,
boolean commit)
Index all the contents in a given workspace.
|
Map<String,Object> |
indexAllResources(String workspaceName,
boolean commit)
Index all the resources in a given workspace.
|
void |
indexContent(String contentId,
boolean indexAttachments)
Add or update a content into Solr index on all workspaces and commit
|
void |
indexContent(String contentId,
String workspaceName,
boolean indexAttachments,
boolean commit)
Add or update a content into Solr index
|
void |
indexContentAttachment(Resource resource,
Content content)
Index a content attachment
|
void |
indexContentAttachments(ResourceCollection collection,
Content content)
Index content attachments as new entries in the idnex
|
SolrIndexer.IndexationResult |
indexContents(Iterable<Content> contents)
Send a collection of contents for indexation in the solr server on all workspaces and commit
|
SolrIndexer.IndexationResult |
indexContents(Iterable<Content> contents,
String workspaceName,
boolean indexAttachments,
boolean commit)
Send a collection of contents for indexation in the solr server.
|
void |
indexResource(Resource resource,
String documentType,
String workspaceName,
boolean commit)
Add or update a resource into Solr index
|
SolrIndexer.IndexationResult |
indexResources(Iterable<? extends AmetysObject> resources,
String documentType,
TraversableAmetysObject resourceRoot,
String workspaceName,
boolean commit)
Send a collection of contents for indexation in the solr server.
|
SolrIndexer.IndexationResult |
indexResources(Iterable<AmetysObject> resources,
String documentType,
String workspaceName,
boolean commit)
Send a collection of contents for indexation in the solr server.
|
void |
indexSubcontents(String collectionId,
boolean indexAttachments)
Add or update the child contents of a
AmetysObjectCollection into Solr index, for all workspaces and commit |
void |
indexSubcontents(String collectionId,
String workspaceName,
boolean indexAttachments,
boolean commit)
Index the child contents of a
AmetysObjectCollection |
void |
initialize() |
void |
optimize(String workspaceName)
Launch a solr index optimization.
|
void |
reloadAclCache()
Reloads the ACL Solr cache for all users
|
void |
reloadAclCache(String workspaceName)
Reloads the ACL Solr cache for all users
|
void |
reloadAclCache(String workspaceName,
boolean checkIfNecessary)
Reloads the ACL Solr cache for all users
|
protected void |
reloadCores()
Reload the solr cores.
|
void |
rollback(String workspaceName)
Process a Solr rollback operation.
|
void |
sendSchema()
Send the schema.
|
void |
service(ServiceManager serviceManager) |
static String |
truncateUtf8StringValue(String value,
Logger logger,
String documentId,
String fieldName)
Truncates (if needed) the given string in order to be indexed without immense term error by Solr.
|
protected void |
unindexAllContents(String workspaceName,
boolean unindexAttachments,
boolean commit)
Unindex all content documents.
|
void |
unindexAllDocuments(String workspaceName,
boolean commit)
Delete all documents from the solr index.
|
void |
unindexAllResources(String workspaceName,
boolean commit)
Delete all resource documents from the solr index.
|
void |
unindexContent(String contentId,
boolean unindexAttachments)
Remove a content from Solr index for all workspaces and commit
|
void |
unindexContent(String contentId,
String workspaceName,
boolean unindexAttachments,
boolean commit)
Remove a content from Solr index
|
void |
unindexContents(Collection<String> contentIds)
Remove a content from Solr index for all workspaces and commit
|
void |
unindexContents(Collection<String> contentIds,
String workspaceName,
boolean commit)
Remove a content from Solr index
|
void |
unindexResource(String resourceId)
Remove a resource from Solr index for all workspaces and commit
|
void |
unindexResource(String resourceId,
String workspaceName,
boolean commit)
Remove a resource from the Solr index.
|
void |
unindexResourcesByPath(String rootId,
String path)
Delete all resource documents at a given path for all workspaces and commit
|
void |
unindexResourcesByPath(String rootId,
String path,
String workspaceName,
boolean commit)
Delete all resource documents at a given path.
|
void |
updateAmetysUrlCoreProperty()
Updates the ametys.url property of the Solr cores.
|
void |
updateSystemProperty(Content content,
String propertyId,
String workspaceName,
boolean commit)
Update the value of a specific system property in a content document.
|
getLogger, setLogger
private static final ThreadLocal<SimpleDateFormat> __DATE_FORMAT
private static final String _CONFIGSET_NAME_PREFIX
private static final List<String> _READ_ONLY_FIELDS
private static final List<String> _READ_ONLY_FIELDTYPES
private static final int __SOLR_STRING_NB_BYTES_LIMIT
protected AmetysObjectResolver _resolver
protected SchemaDefinitionProviderExtensionPoint _schemaDefProviderEP
protected SchemaHelper _schemaHelper
protected SolrContentIndexer _solrContentIndexer
protected SolrWorkflowIndexer _solrWorkflowIndexer
protected SolrResourceIndexer _solrResourceIndexer
protected SolrClientProvider _solrClientProvider
protected String _solrCorePrefix
protected String _ametysInternalUrl
protected WorkspaceSelector _workspaceSelector
public SolrIndexer()
public static SimpleDateFormat dateFormat()
public static String truncateUtf8StringValue(String value, Logger logger, String documentId, String fieldName)
value
- The string value to indexlogger
- The logger for logging in WARN level in case the given string is too long and will be truncated. Can be null if you do not want to log.documentId
- The id of the document being indexed. Can be null if you do not want to log.fieldName
- The name of the field being indexed. Can be null if you do not want to log.public void service(ServiceManager serviceManager) throws ServiceException
service
in interface Serviceable
ServiceException
public void initialize() throws Exception
initialize
in interface Initializable
Exception
public void contextualize(Context context) throws ContextException
contextualize
in interface Contextualizable
ContextException
protected SolrClient _getSolrClient(String workspaceName)
workspaceName
- The name of the workspaceprivate SolrClient _defaultSolrClient()
public Set<String> getCoreNames() throws IOException, SolrServerException
IOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.protected Set<String> getRealCoreNames() throws IOException, SolrServerException
IOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.public void createCore(String name) throws IOException, SolrServerException
name
- The name of the core to create.IOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.public void updateAmetysUrlCoreProperty()
private void _createConfigset(String name) throws IOException, SolrServerException
IOException
SolrServerException
public void deleteCore(String name) throws IOException, SolrServerException
name
- The name of the core to delete.IOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.public void sendSchema() throws IOException, SolrServerException
IOException
- If a communication error occurs.SolrServerException
- If a solr error occurs.protected void addStaticSchemaUpdates(List<org.apache.solr.client.solrj.request.schema.SchemaRequest.Update> updates, org.apache.solr.client.solrj.response.schema.SchemaRepresentation staticSchema, SchemaFields schemaFields)
SchemaRequest.Update
directives from the static schema.updates
- The list of SchemaRequest.Update
directives to fill.staticSchema
- The static schema representation.schemaFields
- The current schema fields, used to track the existing fields (to be filled).protected void addCustomUpdates(List<org.apache.solr.client.solrj.request.schema.SchemaRequest.Update> updates, SchemaFields schemaFields)
SchemaRequest.Update
directives.updates
- The list of SchemaRequest.Update
directives to fill.schemaFields
- The current schema fields, used to track the existing fields (to be filled).protected boolean definitionExists(SchemaDefinition definition, SchemaFields schemaFields)
SchemaFields
reference.definition
- The schema definition to test.schemaFields
- The current schema fields.protected void clearSchema(SolrClient solrClient, String collection) throws IOException, SolrServerException
solrClient
- The Solr clientcollection
- The collection.IOException
- If a communication error occurs.SolrServerException
- If a solr error occurs.protected org.apache.solr.client.solrj.request.schema.SchemaRequest.Update getSchemaUpdate(SchemaDefinition definition)
SchemaRequest.Update
directive from the given schema definition.definition
- The schema definition to add.SchemaRequest.Update
directive.protected void reloadCores() throws IOException, SolrServerException
IOException
- If a communication error occurs.SolrServerException
- If a solr error occurs.public void reloadAclCache() throws IOException, SolrServerException, RepositoryException
IOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.RepositoryException
- If a repository exception occurs when retrieving workspaces.public void reloadAclCache(String workspaceName) throws IOException, SolrServerException
workspaceName
- The workspace nameIOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.public void reloadAclCache(String workspaceName, boolean checkIfNecessary) throws IOException, SolrServerException
workspaceName
- The workspace namecheckIfNecessary
- true to check if the reload is necessary for each segment (i.e. reload only the segments not already in cache)IOException
- If an I/O error occurs.SolrServerException
- If a Solr error occurs.public Map<String,Object> indexAllContents(String workspaceName, boolean indexAttachments, boolean commit) throws Exception
workspaceName
- the workspace where to indexindexAttachments
- to index content attachmentscommit
- true to commitException
- if an error occurs while indexing.protected void unindexAllContents(String workspaceName, boolean unindexAttachments, boolean commit) throws Exception
workspaceName
- The workspace nameunindexAttachments
- also unindex content attachmentscommit
- true to commitException
- if an error occurs while unindexing.public void indexSubcontents(String collectionId, boolean indexAttachments) throws Exception
AmetysObjectCollection
into Solr index, for all workspaces and commitcollectionId
- The id of collectionindexAttachments
- to index content attachmentsException
- if an error occurs while indexing.public void indexSubcontents(String collectionId, String workspaceName, boolean indexAttachments, boolean commit) throws Exception
AmetysObjectCollection
collectionId
- The id of collectionworkspaceName
- the workspace where to indexindexAttachments
- to index content attachmentscommit
- true to commitException
- if an error occurs while unindexing.public void indexContent(String contentId, boolean indexAttachments) throws Exception
contentId
- The id of the content to indexindexAttachments
- to index content attachmentsException
- if an error occurs while indexing.public void indexContent(String contentId, String workspaceName, boolean indexAttachments, boolean commit) throws Exception
contentId
- The id of the content to indexworkspaceName
- the workspace where to indexindexAttachments
- to index content attachmentscommit
- true to commit the indexationException
- if an error occurs while indexing.private void _doIndexContent(Content content, String workspaceName, boolean indexAttachments, boolean commit) throws IndexingException
IndexingException
public SolrIndexer.IndexationResult indexContents(Iterable<Content> contents) throws Exception
contents
- the collection of contents to index.Exception
- if an error occurs while indexing.public SolrIndexer.IndexationResult indexContents(Iterable<Content> contents, String workspaceName, boolean indexAttachments, boolean commit) throws Exception
contents
- the collection of contents to index.workspaceName
- the workspace where to indexindexAttachments
- to index content attachmentscommit
- true to commit the indexationException
- if an error occurs while indexing.protected SolrIndexer.IndexationResult doIndexContents(Iterable<Content> contents, String workspaceName, boolean indexAttachments, boolean commit) throws Exception
contents
- the contents to index.workspaceName
- The workspace nameindexAttachments
- to index content attachmentscommit
- true to commit transactionException
- if an error occurs committing the results.public void updateSystemProperty(Content content, String propertyId, String workspaceName, boolean commit) throws Exception
content
- The content to update.propertyId
- The system property ID.workspaceName
- The workspace namecommit
- true to commit updateException
- if an error occurs while indexing.public void unindexContent(String contentId, boolean unindexAttachments) throws Exception
contentId
- The id of content to unindexunindexAttachments
- also unindex content attachmentsException
- if an error occurs while indexing.public void unindexContent(String contentId, String workspaceName, boolean unindexAttachments, boolean commit) throws Exception
contentId
- The id of content to unindexworkspaceName
- The workspace where to work inunindexAttachments
- also unindex content attachmentscommit
- true to commit operationException
- if an error occurs while indexing.public void unindexContents(Collection<String> contentIds) throws Exception
contentIds
- The id of content to unindexException
- if an error occurs while indexing.public void unindexContents(Collection<String> contentIds, String workspaceName, boolean commit) throws Exception
contentIds
- The id of content to unindexworkspaceName
- The workspace where to work incommit
- true to commitException
- if an error occurs while indexing.protected void doIndexContent(Content content, String workspaceName) throws Exception
content
- The content to indexworkspaceName
- The workspace where to indexException
- if an error occurs while indexing.protected void doIndexContentWorkflow(Content content, String workspaceName, boolean commit) throws Exception
content
- The content.workspaceName
- The workspace namecommit
- true to commit, false otherwise.Exception
- if an error occurs while indexing.public void indexContentAttachments(ResourceCollection collection, Content content) throws Exception
collection
- the collection of attachmentscontent
- the content whose attachments will be indexedException
- if something goes wrong when indexing the attachments of the contentpublic void indexContentAttachment(Resource resource, Content content) throws Exception
private void _indexContentAttachment(Resource resource, SolrInputDocument document, Content content) throws Exception
Exception
protected void _indexResourceDocument(Resource resource, SolrInputDocument document) throws SolrServerException, IOException
resource
- the resource from which the input document is createddocument
- the input documentSolrServerException
- if there is an error on the serverIOException
- if there is a communication error with the serverprotected void deleteRepeaterDocs(String contentId, String workspaceName) throws Exception
workspaceName
- The workspace namecontentId
- the content ID.Exception
- if an error occurs while indexing.public Map<String,Object> indexAllResources(String workspaceName, boolean commit) throws Exception
workspaceName
- The workspace where to indexcommit
- true to commit indexationException
- if an error occurs while indexing.public SolrIndexer.IndexationResult indexResources(Iterable<AmetysObject> resources, String documentType, String workspaceName, boolean commit) throws Exception
resources
- the collection of contents to index.documentType
- The document type of the resourceworkspaceName
- The workspace where to indexcommit
- true to commit indexationException
- if an error occurs while indexing.public SolrIndexer.IndexationResult indexResources(Iterable<? extends AmetysObject> resources, String documentType, TraversableAmetysObject resourceRoot, String workspaceName, boolean commit) throws Exception
resources
- the collection of contents to index.documentType
- The document type of the resourceresourceRoot
- The resource root, can be null. In that case, it will be computed for each resource.workspaceName
- The workspace where to indexcommit
- true to commit indexationException
- if an error occurs while indexing.protected SolrIndexer.IndexationResult doIndexResources(Iterable<? extends AmetysObject> resources, String documentType, TraversableAmetysObject resourceRoot, String workspaceName, boolean commit) throws Exception
resources
- the resources to index.documentType
- The document type of the resourceresourceRoot
- The resource root, can be null. In that case, it will be computed for each resource.workspaceName
- The workspace where to indexcommit
- true to commit indexationException
- if an error occurs committing the results.public void indexResource(Resource resource, String documentType, String workspaceName, boolean commit) throws Exception
resource
- The resource to indexdocumentType
- The document type of the resourceworkspaceName
- The workspace where to indexcommit
- true to commit indexationException
- if an error occurs while indexing.public void unindexAllResources(String workspaceName, boolean commit) throws Exception
workspaceName
- The workspace namecommit
- true to commit deletionException
- If an error occurs while unindexing.public void unindexResourcesByPath(String rootId, String path) throws Exception
rootId
- The resource root ID, must not be null.path
- The resource path relative to the given root, must start with a slash.Exception
- If an error occurs while unindexing.public void unindexResourcesByPath(String rootId, String path, String workspaceName, boolean commit) throws Exception
rootId
- The resource root ID, must not be null.path
- The resource path relative to the given root, must start with a slash.workspaceName
- The workspace where to work incommit
- true to commit operationException
- If an error occurs while unindexing.public void unindexResource(String resourceId) throws Exception
resourceId
- The id of resource to unindexException
- if an error occurs while indexing.public void unindexResource(String resourceId, String workspaceName, boolean commit) throws Exception
resourceId
- The id of resource to unindexworkspaceName
- The workspace where to work incommit
- true to commit operationException
- if an error occurs while unindexing.protected void doIndexExplorerItem(AmetysObject node, String documentType, TraversableAmetysObject resourceRoot) throws Exception
node
- The resource to indexdocumentType
- The document type of the resourceresourceRoot
- The resource root, can be null. In that case, it will be computed for each resource.Exception
- if an error occurs while indexing.protected void doIndexResource(Resource resource, String documentType, TraversableAmetysObject resourceRoot) throws Exception
resource
- The resource to indexdocumentType
- The document type of the resourceresourceRoot
- The resource root, can be null. In that case, it will be computed for each resource.Exception
- if an error occurs while indexing.public void commit() throws SolrServerException, IOException
SolrServerException
- if there is an error on the serverIOException
- if there is a communication error with the serverpublic void commit(String workspaceName) throws SolrServerException, IOException
workspaceName
- The workspace's nameSolrServerException
- if there is an error on the serverIOException
- if there is a communication error with the serverpublic void rollback(String workspaceName) throws SolrServerException, IOException
workspaceName
- The workspace's nameSolrServerException
- if there is an error on the serverIOException
- if there is a communication error with the serverpublic void optimize(String workspaceName) throws SolrServerException, IOException
workspaceName
- The workspace's nameSolrServerException
- if there is an error on the serverIOException
- if there is a communication error with the serverpublic void unindexAllDocuments(String workspaceName, boolean commit) throws Exception
workspaceName
- The workspace namecommit
- true to commitException
- if an error occurs while unindexing.protected void doUnindexDocument(String id, String workspaceName) throws Exception
id
- The id of the document to delete from SolrworkspaceName
- The workspace nameException
- if an error occurs while indexing.protected void doUnindexContentAttachments(String contentId, String workspaceName) throws Exception
contentId
- The id of the contentworkspaceName
- The workspace nameException
- if an error occurs while indexing.