List of usage examples for com.liferay.portal.kernel.search SearchException SearchException
public SearchException(String msg, Throwable cause)
From source file:com.liferay.document.library.repository.cmis.search.BaseCmisSearchQueryBuilder.java
License:Open Source License
protected CMISCriterion buildFieldExpression(String field, String value, CMISSimpleExpressionOperator cmisSimpleExpressionOperator, QueryConfig queryConfig) throws SearchException { CMISCriterion cmisCriterion = null;/*from w w w . j ava2s . co m*/ boolean wildcard = false; if (CMISSimpleExpressionOperator.LIKE == cmisSimpleExpressionOperator) { wildcard = true; } if (field.equals(Field.FOLDER_ID)) { long folderId = GetterUtil.getLong(value); try { RepositoryEntry repositoryEntry = _repositoryEntryLocalService.fetchRepositoryEntry(folderId); if (repositoryEntry != null) { String objectId = repositoryEntry.getMappedId(); objectId = CMISParameterValueUtil.formatParameterValue(field, objectId, wildcard, queryConfig); if (queryConfig.isSearchSubfolders()) { cmisCriterion = new CMISInTreeExpression(objectId); } else { cmisCriterion = new CMISInFolderExpression(objectId); } } } catch (SystemException se) { throw new SearchException("Unable to determine folder {folderId=" + folderId + "}", se); } } else if (field.equals(Field.USER_ID)) { try { long userId = GetterUtil.getLong(value); User user = _userLocalService.getUserById(userId); String screenName = CMISParameterValueUtil.formatParameterValue(field, user.getScreenName(), wildcard, queryConfig); cmisCriterion = new CMISSimpleExpression(getCmisField(field), screenName, cmisSimpleExpressionOperator); } catch (Exception e) { if (e instanceof SearchException) { throw (SearchException) e; } throw new SearchException("Unable to determine user {" + field + "=" + value + "}", e); } } else { value = CMISParameterValueUtil.formatParameterValue(field, value, wildcard, queryConfig); cmisCriterion = new CMISSimpleExpression(getCmisField(field), value, cmisSimpleExpressionOperator); } return cmisCriterion; }
From source file:com.liferay.document.library.repository.external.ExtRepositoryAdapter.java
License:Open Source License
@Override public Hits search(SearchContext searchContext, Query query) throws SearchException { long startTime = System.currentTimeMillis(); List<ExtRepositorySearchResult<?>> extRepositorySearchResults = null; try {// w ww. j a v a 2 s. c om extRepositorySearchResults = _extRepository.search(searchContext, query, new ExtRepositoryQueryMapperImpl(this)); } catch (PortalException | SystemException e) { throw new SearchException("Unable to perform search", e); } QueryConfig queryConfig = searchContext.getQueryConfig(); List<Document> documents = new ArrayList<>(); List<String> snippets = new ArrayList<>(); List<Float> scores = new ArrayList<>(); int total = 0; for (ExtRepositorySearchResult<?> extRepositorySearchResult : extRepositorySearchResults) { try { ExtRepositoryObjectAdapter<?> extRepositoryEntryAdapter = _toExtRepositoryObjectAdapter( ExtRepositoryObjectAdapterType.OBJECT, extRepositorySearchResult.getObject()); Document document = new DocumentImpl(); document.addKeyword(Field.ENTRY_CLASS_NAME, extRepositoryEntryAdapter.getModelClassName()); document.addKeyword(Field.ENTRY_CLASS_PK, extRepositoryEntryAdapter.getPrimaryKey()); document.addKeyword(Field.TITLE, extRepositoryEntryAdapter.getName()); documents.add(document); if (queryConfig.isScoreEnabled()) { scores.add(extRepositorySearchResult.getScore()); } else { scores.add(1.0F); } snippets.add(extRepositorySearchResult.getSnippet()); total++; } catch (PortalException | SystemException e) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", e); } } } float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND; Hits hits = new HitsImpl(); hits.setDocs(documents.toArray(new Document[documents.size()])); hits.setLength(total); hits.setQueryTerms(new String[0]); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime(searchTime); hits.setSnippets(snippets.toArray(new String[snippets.size()])); hits.setStart(startTime); return hits; }
From source file:com.liferay.repository.external.ExtRepositoryAdapter.java
License:Open Source License
@Override public Hits search(SearchContext searchContext, Query query) throws SearchException { long startTime = System.currentTimeMillis(); List<ExtRepositorySearchResult<?>> extRepositorySearchResults = null; try {/*from ww w. j a va 2s . com*/ extRepositorySearchResults = _extRepository.search(searchContext, query, new ExtRepositoryQueryMapperImpl(this)); } catch (PortalException pe) { throw new SearchException("Unable to perform search", pe); } catch (SystemException se) { throw new SearchException("Unable to perform search", se); } QueryConfig queryConfig = searchContext.getQueryConfig(); List<Document> documents = new ArrayList<Document>(); List<String> snippets = new ArrayList<String>(); List<Float> scores = new ArrayList<Float>(); int total = 0; for (ExtRepositorySearchResult<?> extRepositorySearchResult : extRepositorySearchResults) { try { ExtRepositoryObjectAdapter<?> extRepositoryEntryAdapter = _toExtRepositoryObjectAdapter( ExtRepositoryObjectAdapterType.OBJECT, extRepositorySearchResult.getObject()); Document document = new DocumentImpl(); document.addKeyword(Field.ENTRY_CLASS_NAME, extRepositoryEntryAdapter.getModelClassName()); document.addKeyword(Field.ENTRY_CLASS_PK, extRepositoryEntryAdapter.getPrimaryKey()); document.addKeyword(Field.TITLE, extRepositoryEntryAdapter.getName()); documents.add(document); if (queryConfig.isScoreEnabled()) { scores.add(extRepositorySearchResult.getScore()); } else { scores.add(1.0F); } snippets.add(extRepositorySearchResult.getSnippet()); total++; } catch (SystemException se) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", se); } } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Invalid entry returned from search", pe); } } } float searchTime = (float) (System.currentTimeMillis() - startTime) / Time.SECOND; Hits hits = new HitsImpl(); hits.setDocs(documents.toArray(new Document[documents.size()])); hits.setLength(total); hits.setQueryTerms(new String[0]); hits.setScores(ArrayUtil.toFloatArray(scores)); hits.setSearchTime(searchTime); hits.setSnippets(snippets.toArray(new String[snippets.size()])); hits.setStart(startTime); return hits; }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void addDocument(SearchContext searchContext, Document document) throws SearchException { try {/*from w w w .j a v a 2 s . com*/ _log.debug("Adding document with uid " + document.getUID()); IndexRequestBuilder updateRequestBuilder = getUpdateRequestBuilder(searchContext, document); Future<IndexResponse> future = updateRequestBuilder.execute(); IndexResponse updateResponse = future.get(); } catch (Exception e) { _log.debug("Unable to add document with uid " + document.getUID() + "with error: " + e.getMessage()); throw new SearchException("Unable to add document " + document.getUID(), e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void addDocuments(SearchContext searchContext, Collection<Document> documents) throws SearchException { try {//w ww. j av a 2 s .com for (Document document : documents) { try { //Sending each document for indexing instead of bulkRequest. Need to change to use BulkProcessor in a future release addDocument(searchContext, document); } catch (Exception e) { //ignore } } } catch (Exception e) { _log.debug("Unable to add documents " + documents + "with error: " + e.getMessage()); throw new SearchException("Unable to add documents " + documents, e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void deleteDocument(SearchContext searchContext, String uid) throws SearchException { try {// w w w .j a va 2 s . com Client client = getClient(); DeleteRequestBuilder deleteRequestBuilder = client.prepareDelete(Utilities.getIndexName(searchContext), "documents", uid); Future<DeleteResponse> future = deleteRequestBuilder.execute(); DeleteResponse deleteResponse = future.get(); } catch (Exception e) { throw new SearchException("Unable to delete document " + uid, e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void deleteDocuments(SearchContext searchContext, Collection<String> uids) throws SearchException { try {// ww w.ja v a2s . co m Client client = getClient(); BulkRequestBuilder bulkRequestBuilder = client.prepareBulk(); for (String uid : uids) { DeleteRequestBuilder deleteRequestBuilder = client .prepareDelete(Utilities.getIndexName(searchContext), "documents", uid); bulkRequestBuilder.add(deleteRequestBuilder); } Future<BulkResponse> future = bulkRequestBuilder.execute(); BulkResponse bulkResponse = future.get(); if (_log.isDebugEnabled()) { if (bulkResponse.hasFailures()) { _log.debug("Errors while doing bulk delete with errors " + bulkResponse.buildFailureMessage()); } } } catch (Exception e) { throw new SearchException("Unable to delete documents " + uids, e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void deletePortletDocuments(SearchContext searchContext, String portletId) throws SearchException { try {// www . j a va 2s .com Client client = getClient(); DeleteByQueryRequestBuilder deleteByQueryRequestBuilder = new DeleteByQueryRequestBuilder(client, DeleteByQueryAction.INSTANCE); deleteByQueryRequestBuilder.setIndices(Utilities.getIndexName(searchContext)); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(QueryBuilders.termQuery(Field.PORTLET_ID, portletId)); deleteByQueryRequestBuilder.setQuery(boolQueryBuilder); Future<DeleteByQueryResponse> future = deleteByQueryRequestBuilder.execute(); future.get(); } catch (Exception e) { _log.debug("Unable to delete portlet document with id " + portletId + "with error: " + e.getMessage()); throw new SearchException("Unable to delete data for portlet " + portletId, e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void updateDocument(SearchContext searchContext, Document document) throws SearchException { try {// w w w . j av a 2 s . c o m _log.debug("Updating document with uid " + document.getUID()); deleteDocument(searchContext, document.getUID()); IndexRequestBuilder updateRequestBuilder = getUpdateRequestBuilder(searchContext, document); Future<IndexResponse> future = updateRequestBuilder.execute(); IndexResponse updateResponse = future.get(); } catch (Exception e) { _log.debug("Unable to update document with uid " + document.getUID() + "with error: " + e.getMessage()); throw new SearchException("Unable to update document " + document.getUID(), e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexWriter.java
License:Open Source License
@Override public void updateDocuments(SearchContext searchContext, Collection<Document> documents) throws SearchException { try {//ww w.j a v a 2 s. com for (Document document : documents) { try { //Sending each document for indexing instead of bulkRequest. Need to change to use BulkProcessor in a future release updateDocument(searchContext, document); } catch (Exception e) { //ignore } } } catch (Exception e) { _log.debug("Unable to update documents " + documents + "with error: " + e.getMessage()); throw new SearchException("Unable to update documents " + documents, e); } }