/** * Gets the search hits. * * @param searchEngineId the search engine id * @param companyId the company id * @param query the query * @param sort the sort * @param start the start * @param end the end * @return the search hits */ public Hits getSearchHits(String searchEngineId, long companyId, Query query, Sort[] sort, int start, int end) { if (_log.isInfoEnabled()) { _log.info("Search against Elasticsearch with searchEngineId, companyId, query, sort, start and end parameters"); } Hits hits = new HitsImpl(); Client client = this._esConnector.getClient(); SearchRequestBuilder searchRequestBuilder = client .prepareSearch( ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX) .setQuery(_esQueryBuilder.doSearch(query)); SearchResponse response = null; if (getSort(sort) != null) { response = searchRequestBuilder.setFrom(start) .setSize(end) .addSort(getSort(sort)) .execute().actionGet(); } else { response = searchRequestBuilder.setFrom(start) .setSize(end) .execute().actionGet(); } SearchHits searchHits = response.getHits(); hits.setDocs(getDocuments(searchHits)); hits.setScores(getScores(searchHits)); hits.setSearchTime( (float)(System.currentTimeMillis() - hits.getStart()) / Time.SECOND); hits.setQuery(query); hits.setLength((int)searchHits.getTotalHits()); hits.setStart(hits.getStart()); return hits; }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); long userId = backgroundTask.getUserId(); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH); sb.append(Time.getTimestamp()); sb.append(".zip"); File xmlFile = TaskRecordLocalServiceUtil.exportTaskRecordsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), xmlFile); return BackgroundTaskResult.SUCCESS; }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); long userId = backgroundTask.getUserId(); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH); sb.append(Time.getTimestamp()); sb.append(".zip"); File xmlFile = ContactLocalServiceUtil.exportContactsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), xmlFile); return BackgroundTaskResult.SUCCESS; }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws PortalException { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); long userId = backgroundTask.getUserId(); StringBundler sb = new StringBundler(4); sb.append(StringUtil.replace(exportImportConfiguration.getName(), CharPool.SPACE, CharPool.UNDERLINE)); sb.append(StringPool.DASH); sb.append(Time.getTimestamp()); sb.append(".zip"); File xmlFile = MeasurementLocalServiceUtil.exportMeasurementsAsFile(exportImportConfiguration); BackgroundTaskManagerUtil.addBackgroundTaskAttachment(userId, backgroundTask.getBackgroundTaskId(), sb.toString(), xmlFile); return BackgroundTaskResult.SUCCESS; }
/** * Gets the search hits. * * @param searchContext the search context * @param query the query * @return the search hits */ public Hits getSearchHits(SearchContext searchContext, Query query) { if (_log.isInfoEnabled()) { _log.info("Search against Elasticsearch with SearchContext"); } Hits hits = new HitsImpl(); hits.setStart(new Date().getTime()); Client client = this._esConnector.getClient(); String keywords = searchContext.getKeywords(); SearchRequestBuilder searchRequestBuilder = client .prepareSearch( ElasticsearchIndexerConstants.ELASTIC_SEARCH_LIFERAY_INDEX) .setQuery(_esQueryBuilder.doSearch(query)); // Handle Search Facet queries handleFacetQueries(searchContext, searchRequestBuilder); SearchResponse response = null; if (getSort(searchContext.getSorts()) != null) { searchRequestBuilder = searchRequestBuilder.setFrom(searchContext.getStart()) .setSize(searchContext.getEnd()) .addSort(getSort(searchContext.getSorts())); } else { searchRequestBuilder = searchRequestBuilder.setFrom(searchContext.getStart()) .setSize(searchContext.getEnd()); } response = searchRequestBuilder.execute().actionGet(); collectFacetResults(searchContext, response); SearchHits searchHits = response.getHits(); hits.setDocs(getDocuments(searchHits, searchContext)); hits.setScores(getScores(searchHits)); hits.setSearchTime( (float)(System.currentTimeMillis() - hits.getStart()) / Time.SECOND); hits.setQuery(query); if (keywords != null) { hits.setQueryTerms(keywords.split(StringPool.SPACE)); } hits.setLength((int)searchHits.getTotalHits()); hits.setStart(hits.getStart()); return hits; }