/** * Updates the core name to be in sync with the index name. */ private void updateCoreName() { m_coreName = generateCoreName(getName()); }
/** * Returns the name of the current search index.<p> * * @return the name of the current search index */ public String getIndex() { return getSearchIndex().getName(); }
/** * Creates a new index writer based on the provided standard Lucene IndexWriter for the * provided OpenCms search index instance.<p> * * The OpenCms search instance is currently used only for improved logging of the * index operations.<p> * * @param client the standard Lucene IndexWriter to use as delegate * @param index the OpenCms search index instance this writer to supposed to write to */ public CmsSolrIndexWriter(SolrClient client, CmsSolrIndex index) { m_index = index; m_server = client; if (m_index != null) { LOG.info( Messages.get().getBundle().key( Messages.LOG_SOLR_WRITER_CREATE_2, m_index.getName(), m_index.getPath())); } }
/** * @see org.opencms.search.I_CmsIndexWriter#commit() */ public void commit() throws IOException { if ((m_server != null) && (m_index != null)) { try { LOG.info( Messages.get().getBundle().key( Messages.LOG_SOLR_WRITER_COMMIT_2, m_index.getName(), m_index.getPath())); m_server.commit(); } catch (SolrServerException e) { throw new IOException(e.getLocalizedMessage(), e); } } }
/** * Deletes all documents of the index belonging to this index writer.<p> * * @throws IOException if something goes wrong */ public void deleteAllDocuments() throws IOException { if ((m_server != null) && (m_index != null)) { try { LOG.info( Messages.get().getBundle().key( Messages.LOG_SOLR_WRITER_DELETE_ALL_2, m_index.getName(), m_index.getPath())); m_server.deleteByQuery("*:*", m_commitMs); } catch (SolrServerException e) { throw new IOException(e.getLocalizedMessage(), e); } } }
/** * @see org.opencms.search.I_CmsIndexWriter#updateDocument(java.lang.String, org.opencms.search.I_CmsSearchDocument) */ public void updateDocument(String rootPath, I_CmsSearchDocument document) throws IOException { if ((m_server != null) && (m_index != null)) { if (document.getDocument() != null) { try { m_server.deleteByQuery("path:\"" + rootPath + "\"", m_commitMs); } catch (Exception e1) { LOG.error(e1.getLocalizedMessage(), e1); } try { LOG.info( Messages.get().getBundle().key( Messages.LOG_SOLR_WRITER_DOC_UPDATE_3, rootPath, m_index.getName(), m_index.getPath())); m_server.add((SolrInputDocument)document.getDocument(), m_commitMs); } catch (SolrServerException e) { throw new IOException(e.getLocalizedMessage(), e); } } } } }
/** * @see org.opencms.search.I_CmsIndexWriter#deleteDocument(org.opencms.db.CmsPublishedResource) */ public void deleteDocument(CmsPublishedResource resource) throws IOException { if ((m_server != null) && (m_index != null)) { try { LOG.info( Messages.get().getBundle().key( Messages.LOG_SOLR_WRITER_DOC_DELETE_3, resource.getRootPath(), m_index.getName(), m_index.getPath())); m_server.deleteById(resource.getStructureId().toString(), m_commitMs); } catch (SolrServerException e) { throw new IOException(e.getLocalizedMessage(), e); } catch (SolrException e) { throw new IOException(e.getLocalizedMessage(), e); } } }
Messages.get().getBundle().key( Messages.INIT_SOLR_INDEX_DIR_CREATED_2, index.getName(), index.getPath())); m_solrConfig.getHome() + FileSystems.getDefault().getSeparator() + index.getName()); if (!instanceDir.exists()) { instanceDir.mkdirs(); Messages.get().getBundle().key( Messages.INIT_SOLR_INDEX_DIR_CREATED_2, index.getName(), index.getPath())); Messages.get().container( Messages.ERR_SOLR_SERVER_NOT_CREATED_3, index.getName() + " (" + index.getCoreName() + ")", index.getPath(), m_solrConfig.getSolrConfigFile().getAbsolutePath()), Messages.get().getBundle().key( Messages.INIT_SOLR_SERVER_CREATED_1, index.getName() + " (" + index.getCoreName() + ")"));
/** * Checks if the current user is allowed to access non-online indexes.<p> * * To access non-online indexes the current user must be a workplace user at least.<p> * * @param cms the CMS object initialized with the current request context / user * * @throws CmsSearchException thrown if the access is not permitted */ private void checkOfflineAccess(CmsObject cms) throws CmsSearchException { // If an offline index is being selected, check permissions if (!CmsProject.ONLINE_PROJECT_NAME.equals(getProject())) { // only if the user has the role Workplace user, he is allowed to access the Offline index try { OpenCms.getRoleManager().checkRole(cms, CmsRole.ELEMENT_AUTHOR); } catch (CmsRoleViolationException e) { throw new CmsSearchException( Messages.get().container( Messages.LOG_SOLR_ERR_SEARCH_PERMISSION_VIOLATION_2, getName(), cms.getRequestContext().getCurrentUser()), e); } } }