use of org.opencms.search.solr.CmsSolrResultList in project opencms-core by alkacon.
the class CmsJsonDocumentList method getSearchResult.
/**
* Evaluates the list configuration and returns the search result.<p>
*
* @param context the handler context
* @return the search result
* @throws JSONException if something goes wrong
* @throws CmsSearchException if something goes wrong
*/
private CmsSearchResultWrapper getSearchResult(CmsJsonHandlerContext context) throws JSONException, CmsSearchException {
ListConfigurationBean listConfigurationBean = CmsListManager.parseListConfiguration(context.getCms(), context.getResource());
CmsSimpleSearchConfigurationParser searchConfigurationParser = new CmsSimpleSearchConfigurationParser(context.getCms(), listConfigurationBean, "{}");
Locale locale = CmsLocaleManager.getLocale(m_jsonRequest.getParamLocale());
Locale selectedLocale = OpenCms.getLocaleManager().getBestMatchingLocale(locale, Collections.emptyList(), m_xmlContent.getLocales());
searchConfigurationParser.setSearchLocale(selectedLocale);
String paramSort = m_jsonRequest.getParamSort();
if (paramSort != null) {
searchConfigurationParser.setSortOption(paramSort);
}
CmsSolrQuery query = searchConfigurationParser.getInitialQuery();
Integer paramStart = m_jsonRequest.getParamStart();
Integer paramRows = m_jsonRequest.getParamRows();
if (paramStart != null) {
query.setStart(paramStart);
}
if (paramRows != null) {
query.setRows(paramRows);
} else {
query.setRows(MAX_ROWS);
}
CmsSearchController searchController = new CmsSearchController(new CmsSearchConfiguration(searchConfigurationParser, context.getCms()));
searchController.addQueryParts(query, context.getCms());
I_CmsSearchConfigurationCommon searchConfigurationCommon = searchController.getCommon().getConfig();
CmsSolrIndex index = OpenCms.getSearchManager().getIndexSolr(searchConfigurationCommon.getSolrIndex());
CmsSolrResultList solrResultList = index.search(context.getCms(), query, true, null, false, CmsResourceFilter.DEFAULT, searchConfigurationCommon.getMaxReturnedResults());
return new CmsSearchResultWrapper(searchController, solrResultList, query, context.getCms(), null);
}
use of org.opencms.search.solr.CmsSolrResultList in project opencms-core by alkacon.
the class CmsCmisRepository method query.
/**
* @see org.opencms.cmis.I_CmsCmisRepository#query(org.opencms.cmis.CmsCmisCallContext, java.lang.String, boolean, boolean, org.apache.chemistry.opencmis.commons.enums.IncludeRelationships, java.lang.String, java.math.BigInteger, java.math.BigInteger)
*/
@Override
public synchronized ObjectList query(CmsCmisCallContext context, String statement, boolean searchAllVersions, boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount) {
try {
CmsObject cms = getCmsObject(context);
CmsSolrIndex index = getIndex();
CmsCmisResourceHelper helper = getResourceHelper();
// split filter
Set<String> filterCollection = null;
// skip and max
int skip = (skipCount == null ? 0 : skipCount.intValue());
if (skip < 0) {
skip = 0;
}
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
if (max < 0) {
max = Integer.MAX_VALUE;
}
CmsSolrResultList results = solrSearch(cms, index, statement, skip, max);
ObjectListImpl resultObjectList = new ObjectListImpl();
List<ObjectData> objectDataList = new ArrayList<ObjectData>();
resultObjectList.setObjects(objectDataList);
for (CmsResource resource : results) {
// build and add child object
objectDataList.add(helper.collectObjectData(context, cms, resource, filterCollection, renditionFilter, includeAllowableActions, false, includeRelationships));
}
resultObjectList.setHasMoreItems(Boolean.valueOf(!results.isEmpty()));
resultObjectList.setNumItems(BigInteger.valueOf(results.getVisibleHitCount()));
return resultObjectList;
} catch (CmsException e) {
handleCmsException(e);
return null;
}
}
use of org.opencms.search.solr.CmsSolrResultList in project opencms-core by alkacon.
the class TestSearchStateParameters method search.
/**
* Performs a search according to the config.json search configuration.
* @return the search result
* @throws CmsException ...
* @throws IOException ...
* @throws URISyntaxException ...
* @throws JSONException ...
*/
private I_CmsSearchResultWrapper search() throws CmsException, IOException, URISyntaxException, JSONException {
String configString = new String(Files.readAllBytes(Paths.get(getClass().getResource("config.json").toURI())));
I_CmsSearchConfiguration config = new CmsSearchConfiguration(new CmsJSONSearchConfigurationParser(configString), getCmsObject());
I_CmsSearchControllerMain searchController = new CmsSearchController(config);
String indexName = searchController.getCommon().getConfig().getSolrIndex();
// try to use configured index
CmsSolrIndex index = null;
if ((indexName != null) && !indexName.trim().isEmpty()) {
index = OpenCms.getSearchManager().getIndexSolr(indexName);
}
// if not successful, use the following default
if (index == null) {
index = OpenCms.getSearchManager().getIndexSolr(CmsSolrIndex.DEFAULT_INDEX_NAME_ONLINE);
}
Map<String, String[]> parameterMap = new HashMap<>();
searchController.updateFromRequestParameters(parameterMap, false);
I_CmsSearchControllerCommon common = searchController.getCommon();
CmsSearchResultWrapper searchResult = null;
// Do not search for empty query, if configured
if (common.getState().getQuery().isEmpty() && (!common.getConfig().getIgnoreQueryParam() && !common.getConfig().getSearchForEmptyQueryParam())) {
searchResult = new CmsSearchResultWrapper(searchController, null, null, getCmsObject(), null);
} else {
CmsSolrQuery query = new CmsSolrQuery(null, null);
searchController.addQueryParts(query, getCmsObject());
// use "complicated" constructor to allow more than 50 results -> set ignoreMaxResults to true
// also set resource filter to allow for returning unreleased/expired resources if necessary.
CmsSolrResultList solrResultList = index.search(getCmsObject(), // use a clone of the query, since the search function manipulates the query (removes highlighting parts), but we want to keep the original one.
query.clone(), true, null, false, CmsResourceFilter.IGNORE_EXPIRATION, searchController.getCommon().getConfig().getMaxReturnedResults());
searchResult = new CmsSearchResultWrapper(searchController, solrResultList, query, getCmsObject(), null);
}
return searchResult;
}
use of org.opencms.search.solr.CmsSolrResultList in project opencms-core by alkacon.
the class TestSimpleSearch method searchForConfig.
/**
* Helper to read the list configuration and perform the search.
* @param cms the context
* @param listName the filename of the list configuration to use for the search.
* @return the list of filenames of the found resources.
* @throws CmsException if something unexpected goes wrong, e.g., the list config does not exist.
*/
private Set<String> searchForConfig(CmsObject cms, String listName) throws CmsException {
CmsResource listConfig = cms.readResource(CmsStringUtil.joinPaths(LIST_BASE_FOLDER, listName));
ListConfigurationBean listConfigBean = CmsListManager.parseListConfiguration(cms, listConfig);
I_CmsSearchConfiguration config = new CmsSearchConfiguration(CmsSimpleSearchConfigurationParser.createInstanceWithNoJsonConfig(getCmsObject(), listConfigBean), cms);
I_CmsSearchController controller = new CmsSearchController(config);
CmsSolrIndex index = OpenCms.getSearchManager().getIndexSolr(CmsSolrIndex.DEFAULT_INDEX_NAME_ONLINE);
CmsSolrQuery query = new CmsSolrQuery();
controller.addQueryParts(query, cms);
CmsSolrResultList searchResult = index.search(cms, query.clone(), true, null, false, null, config.getGeneralConfig().getMaxReturnedResults());
Set<String> result = new HashSet<>(searchResult.size());
for (CmsSearchResource res : searchResult) {
result.add(res.getName());
}
return result;
}
use of org.opencms.search.solr.CmsSolrResultList in project opencms-core by alkacon.
the class CmsListManager method getPublishResources.
/**
* Returns the resources to publish for the current list.<p>
*
* @return the publish resources
*/
List<CmsResource> getPublishResources() {
List<CmsResource> result = new ArrayList<CmsResource>();
if (m_currentResource != null) {
result.add(m_currentResource);
CmsObject cms = A_CmsUI.getCmsObject();
CmsSolrQuery query = m_currentConfigParser.getInitialQuery();
CmsSearchController controller = new CmsSearchController(new CmsSearchConfiguration(m_currentConfigParser, A_CmsUI.getCmsObject()));
controller.getPagination().getState().setCurrentPage(1);
controller.addQueryParts(query, A_CmsUI.getCmsObject());
I_CmsSearchConfigurationCommon commonConfig = controller.getCommon().getConfig();
CmsSolrIndex index = OpenCms.getSearchManager().getIndexSolr(commonConfig.getSolrIndex());
try {
CmsSolrResultList solrResultList = index.search(cms, query, true, null, false, CmsResourceFilter.IGNORE_EXPIRATION, commonConfig.getMaxReturnedResults());
result.addAll(solrResultList);
} catch (CmsSearchException e) {
LOG.error("Error reading resources for publish.", e);
}
}
return result;
}
Aggregations