/** * Default search method.<p> * * @param cms the current CMS object * @param query the query * * @return the results * * @throws CmsSearchException if something goes wrong * * @see #search(CmsObject, String) */ public CmsSolrResultList search(CmsObject cms, CmsSolrQuery query) throws CmsSearchException { return search(cms, query, false); }
/** * Updates the core name to be in sync with the index name. */ private void updateCoreName() { m_coreName = generateCoreName(getName()); }
/** * Returns the resource type for the given root path.<p> * * @param cms the current CMS context * @param rootPath the root path of the resource to get the type for * * @return the resource type for the given root path */ public static final String getType(CmsObject cms, String rootPath) { String type = null; CmsSolrIndex index = CmsSearchManager.getIndexSolr(cms, null); if (index != null) { I_CmsSearchDocument doc = index.getDocument(CmsSearchField.FIELD_PATH, rootPath); if (doc != null) { type = doc.getFieldValueAsString(CmsSearchField.FIELD_TYPE); } } return type; }
/** * 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.CmsSearchIndex#initialize() */ @Override public void initialize() throws CmsSearchException { super.initialize(); getFieldConfiguration().init(); try { OpenCms.getSearchManager().registerSolrIndex(this); } catch (CmsConfigurationException ex) { LOG.error(ex.getMessage(), ex); setEnabled(false); } }
checkOfflineAccess(cms); if (!ignoreSearchExclude) { query.addFilterQuery(CmsSearchField.FIELD_SEARCH_EXCLUDE + ":\"false\""); if (getPriority() > 0) { Thread.currentThread().setPriority(getPriority()); SolrDocument doc = queryResponse.getResults().get(i); CmsSolrDocument searchDoc = new CmsSolrDocument(doc); if (needsPermissionCheck(searchDoc)) { ? getResource(searchCms, searchDoc) : getResource(searchCms, searchDoc, filter); if (resource != null) { long highlightEndTime = System.currentTimeMillis(); SolrCore core = m_solr instanceof EmbeddedSolrServer ? ((EmbeddedSolrServer)m_solr).getCoreContainer().getCore(getCoreName()) : null; CmsSolrResultList result = null; writeResp(response, solrQueryRequest, solrQueryResponse);
index.setSolrServer(new HttpSolrClient(m_solrConfig.getServerUrl())); if (!m_coreContainer.getCoreNames().contains(index.getCoreName())) { File dataDir = new File(index.getPath()); if (!dataDir.exists()) { dataDir.mkdirs(); 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())); properties.put(CoreDescriptor.CORE_DATADIR, dataDir.getAbsolutePath()); properties.put(CoreDescriptor.CORE_CONFIGSET, "default"); core = m_coreContainer.create(index.getCoreName(), instanceDir.toPath(), properties); } catch (NullPointerException e) { if (core != null) { Messages.get().container(
SolrDocument doc = queryResponse.getResults().get(i); CmsSolrDocument searchDoc = new CmsSolrDocument(doc); if (needsPermissionCheck(searchDoc)) { CmsResource resource = getResource(cms, searchDoc); if (resource != null) { ? ((EmbeddedSolrServer)m_solr).getCoreContainer().getCore(getCoreName()) : null; writeResp(res, solrQueryRequest, solrQueryResponse);
/** * 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); } } }
/** * @see org.opencms.search.CmsSearchIndex#createIndexBackup() */ @Override protected String createIndexBackup() { if (!isBackupReindexing()) { // if no backup is generated we don't need to do anything return null; } if (m_solr instanceof EmbeddedSolrServer) { EmbeddedSolrServer ser = (EmbeddedSolrServer)m_solr; CoreContainer con = ser.getCoreContainer(); SolrCore core = con.getCore(getCoreName()); if (core != null) { try { SolrRequestHandler h = core.getRequestHandler("/replication"); if (h instanceof ReplicationHandler) { h.handleRequest( new LocalSolrQueryRequest(core, CmsRequestUtil.createParameterMap("?command=backup")), new SolrQueryResponse()); } } finally { core.close(); } } } return null; }
SolrCore core = ((EmbeddedSolrServer)m_solr).getCoreContainer().getCore(getCoreName()); Writer out = null; try {
/** * Returns the gallery search result list.<p> * * @param params the gallery search parameters * * @return the gallery search result list * * @throws CmsException if the search failed */ public CmsGallerySearchResultList getResult(CmsGallerySearchParameters params) throws CmsException { CmsGallerySearchResultList result = null; if ((m_cms == null) || (m_index == null)) { throw new CmsException(Messages.get().container(Messages.ERR_SEARCH_NOT_INITIALIZED_0)); } result = m_index.gallerySearch(m_cms, params); if (result.size() > 0) { result.calculatePages(params.getResultPage(), params.getMatchesPerPage()); } else { result = new CmsGallerySearchResultList(); } return result; }
/** * @see org.opencms.search.CmsSearchIndex#getConfiguration() */ @Override public CmsParameterConfiguration getConfiguration() { CmsParameterConfiguration result = super.getConfiguration(); if (getPostProcessor() != null) { result.put(POST_PROCESSOR, getPostProcessor().getClass().getName()); } return result; }
/** * Returns the name of the current search index.<p> * * @return the name of the current search index */ public String getIndex() { return getSearchIndex().getName(); }
/** * @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); } } }
/** * Removes a search index from the configuration.<p> * * @param searchIndex the search index to remove */ public void removeSearchIndex(CmsSearchIndex searchIndex) { // shut down index to remove potential config files of Solr indexes searchIndex.shutDown(); if (searchIndex instanceof CmsSolrIndex) { CmsSolrIndex solrIndex = (CmsSolrIndex)searchIndex; m_coreContainer.unload(solrIndex.getCoreName(), true, true, true); } m_indexes.remove(searchIndex); initOfflineIndexes(); if (LOG.isInfoEnabled()) { LOG.info( Messages.get().getBundle().key( Messages.LOG_REMOVE_SEARCH_INDEX_2, searchIndex.getName(), searchIndex.getProject())); } }
"Solr Offline").gallerySearch(searchCms, params); searchResults.calculatePages(params.getResultPage(), params.getMatchesPerPage());
/** * Like {@link #search(CmsObject, CmsSolrQuery, boolean)}, but additionally a resource filter can be specified. * By default, the filter depends on the index. * * @param cms the current OpenCms context * @param ignoreMaxRows <code>true</code> to return all all requested rows, <code>false</code> to use max rows * @param query the OpenCms Solr query * @param filter the resource filter to use for post-processing. * * @return the list of documents found. * * @throws CmsSearchException if something goes wrong */ public CmsSolrResultList search( CmsObject cms, final CmsSolrQuery query, boolean ignoreMaxRows, final CmsResourceFilter filter) throws CmsSearchException { return search(cms, query, ignoreMaxRows, null, false, filter); }
/** * 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); } } }
/** * Searches by structure id.<p> * * @param path the resource path * @param locale the locale for which the search result should be returned * * @return the search result * * @throws CmsException if something goes wrong */ public CmsGallerySearchResult searchByPath(String path, Locale locale) throws CmsException { I_CmsSearchDocument sDoc = m_index.getDocument(CmsSearchField.FIELD_PATH, path); CmsGallerySearchResult result = null; if ((sDoc != null) && (sDoc.getDocument() != null)) { result = new CmsGallerySearchResult(sDoc, m_cms, 100, locale); } else { CmsResource res = m_cms.readResource(path, CmsResourceFilter.IGNORE_EXPIRATION); result = new CmsGallerySearchResult(m_cms, res); } return result; }