List of usage examples for com.liferay.portal.kernel.search SearchException SearchException
public SearchException(Throwable cause)
From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppServiceImpl.java
License:Open Source License
public Hits search(long repositoryId, SearchContext searchContext) throws SearchException { try {//ww w .ja va2 s . co m Repository repository = getRepository(repositoryId); return repository.search(searchContext); } catch (Exception e) { throw new SearchException(e); } }
From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppServiceImpl.java
License:Open Source License
public Hits search(long repositoryId, SearchContext searchContext, Query query) throws SearchException { try {/* w w w . ja v a2s .c om*/ Repository repository = getRepository(repositoryId); return repository.search(searchContext, query); } catch (Exception e) { throw new SearchException(e); } }
From source file:com.liferay.portlet.documentlibrary.util.DLFileEntryIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; _log.info("COGNIZANT@@@@doGetDocument::::: TILE::::" + dlFileEntry.getTitle() + "FileEntryID::::" + dlFileEntry.getFileEntryId()); if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }/*from w w w . j a v a 2 s. c om*/ boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH1:::::" + dlFileEntry.getFileEntryId() + "@@@@@" + dlFileEntry.getTitle() + "@@@@", e); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); try { Document document = getBaseModelDocument(PORTLET_ID, dlFileEntry, dlFileVersion); if (indexContent) { if (is != null) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } else if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } } document.addKeyword(Field.CLASS_TYPE_ID, dlFileEntry.getFileEntryTypeId()); document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.HIDDEN, dlFileEntry.isInHiddenFolder()); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addText(Field.TITLE, dlFileEntry.getTitle()); document.addKeyword(Field.TREE_PATH, StringUtil.split(dlFileEntry.getTreePath(), CharPool.SLASH)); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addText("ddmContent", extractContent(dlFileVersion, LocaleUtil.getSiteDefault())); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("mimeType", StringUtil.replace(dlFileEntry.getMimeType(), CharPool.FORWARD_SLASH, CharPool.UNDERLINE)); document.addKeyword("path", dlFileEntry.getTitle()); document.addKeyword("readCount", dlFileEntry.getReadCount()); document.addKeyword("size", dlFileEntry.getSize()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (dlFileEntry.isInHiddenFolder()) { try { Repository repository = RepositoryLocalServiceUtil.getRepository(dlFileEntry.getRepositoryId()); String portletId = repository.getPortletId(); for (Indexer indexer : IndexerRegistryUtil.getIndexers()) { if (portletId.equals(indexer.getPortletId())) { indexer.addRelatedEntryFields(document, obj); } } } catch (Exception e) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH2:::" + dlFileEntry.getFileEntryId() + "@@@@" + dlFileEntry.getTitle() + "@@@@", e); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } } if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { _log.error("COGNIZANT@@@@doGetDocument@@CATCH3:::" + dlFileEntry.getFileEntryId() + "@@@@" + dlFileEntry.getTitle() + "@@@@", ioe); fileLog.error("FileEntry ID" + dlFileEntry.getFileEntryId()); try { fileWriter = generateCsvFile(dlFileEntry.getFileEntryId(), fileCsvpath); } catch (IOException e1) { _log.error("Error Generating CSV", e1); } } } } }
From source file:com.liferay.portlet.documentlibrary.util.DLIndexer.java
License:Open Source License
@Override protected Document doGetDocument(Object obj) throws Exception { DLFileEntry dlFileEntry = (DLFileEntry) obj; if (_log.isDebugEnabled()) { _log.debug("Indexing document " + dlFileEntry); }/*from w w w . j a va 2 s. c om*/ boolean indexContent = true; InputStream is = null; try { if (PropsValues.DL_FILE_INDEXING_MAX_SIZE == 0) { indexContent = false; } else if (PropsValues.DL_FILE_INDEXING_MAX_SIZE != -1) { if (dlFileEntry.getSize() > PropsValues.DL_FILE_INDEXING_MAX_SIZE) { indexContent = false; } } if (indexContent) { String[] ignoreExtensions = PrefsPropsUtil .getStringArray(PropsKeys.DL_FILE_INDEXING_IGNORE_EXTENSIONS, StringPool.COMMA); if (ArrayUtil.contains(ignoreExtensions, StringPool.PERIOD + dlFileEntry.getExtension())) { indexContent = false; } } if (indexContent) { is = dlFileEntry.getFileVersion().getContentStream(false); } } catch (Exception e) { } if (indexContent && (is == null)) { if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " does not have any content"); } return null; } try { Document document = new DocumentImpl(); long fileEntryId = dlFileEntry.getFileEntryId(); document.addUID(PORTLET_ID, fileEntryId); List<AssetCategory> assetCategories = AssetCategoryLocalServiceUtil .getCategories(DLFileEntry.class.getName(), fileEntryId); long[] assetCategoryIds = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.CATEGORY_ID_ACCESSOR), 0L); document.addKeyword(Field.ASSET_CATEGORY_IDS, assetCategoryIds); String[] assetCategoryNames = StringUtil .split(ListUtil.toString(assetCategories, AssetCategory.NAME_ACCESSOR)); document.addKeyword(Field.ASSET_CATEGORY_NAMES, assetCategoryNames); String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(DLFileEntry.class.getName(), fileEntryId); document.addKeyword(Field.ASSET_TAG_NAMES, assetTagNames); document.addKeyword(Field.COMPANY_ID, dlFileEntry.getCompanyId()); if (indexContent) { try { document.addFile(Field.CONTENT, is, dlFileEntry.getTitle()); } catch (IOException ioe) { throw new SearchException("Cannot extract text from file" + dlFileEntry); } } document.addText(Field.DESCRIPTION, dlFileEntry.getDescription()); document.addKeyword(Field.ENTRY_CLASS_NAME, DLFileEntry.class.getName()); document.addKeyword(Field.ENTRY_CLASS_PK, fileEntryId); document.addKeyword(Field.FOLDER_ID, dlFileEntry.getFolderId()); document.addKeyword(Field.GROUP_ID, getParentGroupId(dlFileEntry.getGroupId())); document.addDate(Field.MODIFIED_DATE, dlFileEntry.getModifiedDate()); document.addKeyword(Field.PORTLET_ID, PORTLET_ID); document.addText(Field.PROPERTIES, dlFileEntry.getLuceneProperties()); document.addKeyword(Field.SCOPE_GROUP_ID, dlFileEntry.getGroupId()); DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); document.addKeyword(Field.STATUS, dlFileVersion.getStatus()); document.addText(Field.TITLE, dlFileEntry.getTitle()); long userId = dlFileEntry.getUserId(); document.addKeyword(Field.USER_ID, userId); document.addKeyword(Field.USER_NAME, PortalUtil.getUserName(userId, dlFileEntry.getUserName()), true); document.addKeyword("dataRepositoryId", dlFileEntry.getDataRepositoryId()); document.addKeyword("extension", dlFileEntry.getExtension()); document.addKeyword("fileEntryTypeId", dlFileEntry.getFileEntryTypeId()); document.addKeyword("path", dlFileEntry.getTitle()); ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(dlFileEntry.getCompanyId(), DLFileEntry.class.getName(), dlFileVersion.getFileVersionId()); ExpandoBridgeIndexerUtil.addAttributes(document, expandoBridge); addFileEntryTypeAttributes(document, dlFileVersion); if (_log.isDebugEnabled()) { _log.debug("Document " + dlFileEntry + " indexed successfully"); } return document; } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { } } } }
From source file:com.liferay.trash.internal.search.TrashIndexer.java
License:Open Source License
@Override public BooleanQuery getFullQuery(SearchContext searchContext) throws SearchException { try {//from ww w . ja va 2s . c o m BooleanFilter fullQueryBooleanFilter = new BooleanFilter(); fullQueryBooleanFilter.addRequiredTerm(Field.COMPANY_ID, searchContext.getCompanyId()); List<TrashHandler> trashHandlers = TrashHandlerRegistryUtil.getTrashHandlers(); for (TrashHandler trashHandler : trashHandlers) { Filter filter = trashHandler.getExcludeFilter(searchContext); if (filter != null) { fullQueryBooleanFilter.add(filter, BooleanClauseOccur.MUST_NOT); } processTrashHandlerExcludeQuery(searchContext, fullQueryBooleanFilter, trashHandler); } long[] groupIds = searchContext.getGroupIds(); if (ArrayUtil.isNotEmpty(groupIds)) { TermsFilter groupTermsFilter = new TermsFilter(Field.GROUP_ID); groupTermsFilter.addValues(ArrayUtil.toStringArray(groupIds)); fullQueryBooleanFilter.add(groupTermsFilter, BooleanClauseOccur.MUST); } fullQueryBooleanFilter.addRequiredTerm(Field.STATUS, WorkflowConstants.STATUS_IN_TRASH); BooleanQuery fullQuery = createFullQuery(fullQueryBooleanFilter, searchContext); return fullQuery; } catch (SearchException se) { throw se; } catch (Exception e) { throw new SearchException(e); } }
From source file:com.rivetlogic.portal.search.elasticsearch.ElasticsearchIndexWriterImpl.java
License:Open Source License
public void deletePortletDocuments(SearchContext searchContext, String portletId) throws SearchException { if (_log.isDebugEnabled()) { _log.debug("Delete portlet documents from elasticsearch indexing"); }/*from ww w . j ava2s. c o m*/ throw new SearchException("Portlet deployment documents are not supported"); }
From source file:com.rivetlogic.portal.search.elasticsearch.ElasticsearchIndexWriterImpl.java
License:Open Source License
/** * Process it./*from ww w. j a v a 2 s . c o m*/ * * @param document * the document * @throws SearchException * the search exception */ private void processIt(Document document) throws SearchException { if (_log.isDebugEnabled()) { _log.debug("Processing document for elasticsearch indexing"); } try { ElasticserachJSONDocument elasticserachJSONDocument = _indexer.processDocument(document); writeIndex(elasticserachJSONDocument); } catch (ElasticsearchIndexingException e) { throw new SearchException(e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java
License:Open Source License
@Override public Hits search(SearchContext searchContext, Query query) throws SearchException { try {// ww w . j av a 2s.co m int end = searchContext.getEnd(); int start = searchContext.getStart(); if (isFilterSearch(searchContext)) { if (end > INDEX_FILTER_SEARCH_LIMIT) { end = end - INDEX_FILTER_SEARCH_LIMIT + 5; } if ((start < 0) || (start > end) || end < 0) { return new HitsImpl(); } } query = getPermissionQuery(searchContext, query); return doSearch(searchContext, query, start, end); } catch (Exception e) { throw new SearchException(e); } }
From source file:com.rknowsys.portal.search.elastic.ElasticsearchIndexSearcher.java
License:Open Source License
@Override public Hits search(String searchEngineId, long companyId, Query query, Sort[] sort, int start, int end) throws SearchException { try {// www. ja v a 2s.c om Client client = getClient(); SearchRequestBuilder searchRequestBuilder = client.prepareSearch(Utilities.getIndexName(companyId)); String q = applyCustomESRules(query.toString()); QueryBuilder queryBuilder = QueryBuilders.queryStringQuery(q); searchRequestBuilder.setQuery(queryBuilder); searchRequestBuilder.setTypes("documents"); addSortToSearch(sort, searchRequestBuilder); _log.debug("Search Start: " + start + " Search End: " + end); if ((start != QueryUtil.ALL_POS) && (end != QueryUtil.ALL_POS)) { searchRequestBuilder.setFrom(start).setSize(end - start); } _log.debug("Query String" + searchRequestBuilder.toString()); SearchRequest searchRequest = searchRequestBuilder.request(); _log.debug("Search query String " + searchRequest.toString()); ActionFuture<SearchResponse> future = client.search(searchRequest); SearchResponse searchResponse = future.actionGet(); Hits hits = processSearchHits(searchResponse, query.getQueryConfig()); hits.setQuery(query); TimeValue timeValue = searchResponse.getTook(); hits.setSearchTime((float) timeValue.getSecondsFrac()); return hits; } catch (Exception e) { throw new SearchException(e); } }
From source file:com.vportal.portal.search.HitsOpenSearchImpl.java
License:Open Source License
public String search(HttpServletRequest request, long groupId, long userId, String keywords, int startPage, int itemsPerPage, String format) throws SearchException { try {/* w w w . ja v a 2s . co m*/ ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); int start = (startPage * itemsPerPage) - itemsPerPage; int end = startPage * itemsPerPage; SearchContext searchContext = SearchContextFactory.getInstance(request); searchContext.setGroupIds(new long[] { groupId }); searchContext.setEnd(end); searchContext.setKeywords(keywords); searchContext.setScopeStrict(false); searchContext.setStart(start); searchContext.setUserId(userId); addSearchAttributes(themeDisplay.getCompanyId(), searchContext, keywords); Portlet portlet = PortletLocalServiceUtil.getPortletById(themeDisplay.getCompanyId(), getPortletId()); Indexer indexer = portlet.getIndexerInstance(); Hits results = indexer.search(searchContext); String[] queryTerms = results.getQueryTerms(); int total = results.getLength(); Object[] values = addSearchResults(queryTerms, keywords, startPage, itemsPerPage, total, start, getTitle(keywords), getSearchPath(), format, themeDisplay); com.liferay.portal.kernel.xml.Document doc = (com.liferay.portal.kernel.xml.Document) values[0]; Element root = (Element) values[1]; for (int i = 0; i < results.getDocs().length; i++) { Document result = results.doc(i); String portletId = result.get(Field.PORTLET_ID); String snippet = results.snippet(i); long resultGroupId = GetterUtil.getLong(result.get(Field.GROUP_ID)); PortletURL portletURL = getPortletURL(request, portletId, resultGroupId); Summary summary = getSummary(indexer, result, snippet, portletURL); String title = summary.getTitle(); String url = getURL(themeDisplay, resultGroupId, result, portletURL); Date modifedDate = result.getDate(Field.MODIFIED); String content = summary.getContent(); String[] tags = new String[0]; Field assetTagNamesField = result.getFields().get(Field.ASSET_TAG_NAMES); if (assetTagNamesField != null) { tags = assetTagNamesField.getValues(); } double ratings = 0.0; String entryClassName = result.get(Field.ENTRY_CLASS_NAME); long entryClassPK = GetterUtil.getLong(result.get(Field.ENTRY_CLASS_PK)); if ((Validator.isNotNull(entryClassName)) && (entryClassPK > 0)) { RatingsStats stats = RatingsStatsLocalServiceUtil.getStats(entryClassName, entryClassPK); ratings = stats.getTotalScore(); } double score = results.score(i); addSearchResult(root, resultGroupId, entryClassName, entryClassPK, title, url, modifedDate, content, tags, ratings, score, format); } if (_log.isDebugEnabled()) { _log.debug("Return\n" + doc.asXML()); } return doc.asXML(); } catch (Exception e) { throw new SearchException(e); } }