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 String |
_CONFIGSET_NAME |
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 SolrContentRightIndexer |
_solrContentRightIndexer
Solr right 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 SolrClient |
_defaultSolrClient() |
private void |
_doIndexContent(Content content,
String workspaceName,
boolean commit) |
protected SolrClient |
_getSolrClient(String workspaceName)
Gets the Solr client
|
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(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 void |
doIndexContentAcls(Content content,
SolrInputDocument document)
Index the users and groups who are allowed to access the content.
|
protected SolrIndexer.IndexationResult |
doIndexContents(Iterable<Content> contents,
String workspaceName,
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 |
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 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)
Add or update a content into Solr index on all workspaces and commit
|
void |
indexContent(String contentId,
String workspaceName,
boolean commit)
Add or update a content into Solr index
|
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 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)
Add or update the child contents of a
AmetysObjectCollection into Solr index, for all workspaces and commit |
void |
indexSubcontents(String collectionId,
String workspaceName,
boolean commit)
Index the child contents of a
AmetysObjectCollection |
void |
initialize() |
void |
optimize(String workspaceName)
Launch a solr index optimization.
|
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) |
protected void |
unindexAllContents(String workspaceName,
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)
Remove a content from Solr index for all workspaces and commit
|
void |
unindexContent(String contentId,
String workspaceName,
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 |
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
private static final List<String> _READ_ONLY_FIELDS
private static final List<String> _READ_ONLY_FIELDTYPES
protected AmetysObjectResolver _resolver
protected SchemaDefinitionProviderExtensionPoint _schemaDefProviderEP
protected SchemaHelper _schemaHelper
protected SolrContentIndexer _solrContentIndexer
protected SolrWorkflowIndexer _solrWorkflowIndexer
protected SolrContentRightIndexer _solrContentRightIndexer
protected SolrResourceIndexer _solrResourceIndexer
protected SolrClientProvider _solrClientProvider
protected String _solrCorePrefix
protected WorkspaceSelector _workspaceSelector
public SolrIndexer()
public static SimpleDateFormat dateFormat()
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 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 Map<String,Object> indexAllContents(String workspaceName, boolean commit) throws Exception
workspaceName
- the workspace where to indexcommit
- true to commitException
- if an error occurs while indexing.protected void unindexAllContents(String workspaceName, boolean commit) throws Exception
workspaceName
- The workspace namecommit
- true to commitException
- if an error occurs while unindexing.public void indexSubcontents(String collectionId) throws Exception
AmetysObjectCollection
into Solr index, for all workspaces and commitcollectionId
- The id of collectionException
- if an error occurs while indexing.public void indexSubcontents(String collectionId, String workspaceName, boolean commit) throws Exception
AmetysObjectCollection
collectionId
- The id of collectionworkspaceName
- the workspace where to indexcommit
- true to commitException
- if an error occurs while unindexing.public void indexContent(String contentId) throws Exception
contentId
- The id of the content to indexException
- if an error occurs while indexing.public void indexContent(String contentId, String workspaceName, boolean commit) throws Exception
contentId
- The id of the content to indexworkspaceName
- the workspace where to indexcommit
- true to commit the indexationException
- if an error occurs while indexing.private void _doIndexContent(Content content, String workspaceName, 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 commit) throws Exception
contents
- the collection of contents to index.workspaceName
- the workspace where to indexcommit
- true to commit the indexationException
- if an error occurs while indexing.protected SolrIndexer.IndexationResult doIndexContents(Iterable<Content> contents, String workspaceName, boolean commit) throws Exception
contents
- the contents to index.workspaceName
- The workspace namecommit
- 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) throws Exception
contentId
- The id of content to unindexException
- if an error occurs while indexing.public void unindexContent(String contentId, String workspaceName, boolean commit) throws Exception
contentId
- The id of content to unindexworkspaceName
- The workspace where to work incommit
- 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 doIndexContentAcls(Content content, SolrInputDocument document) throws Exception
content
- The content.document
- The document.Exception
- 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.protected 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(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.