Search in sources :

Example 1 with CmsSolrResultList

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);
}
Also used : Locale(java.util.Locale) CmsSearchController(org.opencms.jsp.search.controller.CmsSearchController) I_CmsSearchConfigurationCommon(org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon) CmsSolrIndex(org.opencms.search.solr.CmsSolrIndex) CmsSolrQuery(org.opencms.search.solr.CmsSolrQuery) CmsSearchConfiguration(org.opencms.jsp.search.config.CmsSearchConfiguration) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList) ListConfigurationBean(org.opencms.ui.apps.lists.CmsListManager.ListConfigurationBean) CmsSimpleSearchConfigurationParser(org.opencms.jsp.search.config.parser.CmsSimpleSearchConfigurationParser) CmsSearchResultWrapper(org.opencms.jsp.search.result.CmsSearchResultWrapper)

Example 2 with CmsSolrResultList

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;
    }
}
Also used : ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl) CmsObject(org.opencms.file.CmsObject) CmsResource(org.opencms.file.CmsResource) CmsSolrIndex(org.opencms.search.solr.CmsSolrIndex) CmsException(org.opencms.main.CmsException) CmsCmisUtil.handleCmsException(org.opencms.cmis.CmsCmisUtil.handleCmsException) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList)

Example 3 with CmsSolrResultList

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;
}
Also used : CmsSearchController(org.opencms.jsp.search.controller.CmsSearchController) CmsJSONSearchConfigurationParser(org.opencms.jsp.search.config.parser.CmsJSONSearchConfigurationParser) HashMap(java.util.HashMap) I_CmsSearchConfiguration(org.opencms.jsp.search.config.I_CmsSearchConfiguration) I_CmsSearchControllerMain(org.opencms.jsp.search.controller.I_CmsSearchControllerMain) I_CmsSearchControllerCommon(org.opencms.jsp.search.controller.I_CmsSearchControllerCommon) CmsSolrIndex(org.opencms.search.solr.CmsSolrIndex) CmsSolrQuery(org.opencms.search.solr.CmsSolrQuery) I_CmsSearchConfiguration(org.opencms.jsp.search.config.I_CmsSearchConfiguration) CmsSearchConfiguration(org.opencms.jsp.search.config.CmsSearchConfiguration) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList)

Example 4 with CmsSolrResultList

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;
}
Also used : CmsSearchController(org.opencms.jsp.search.controller.CmsSearchController) I_CmsSearchController(org.opencms.jsp.search.controller.I_CmsSearchController) CmsSearchResource(org.opencms.search.CmsSearchResource) I_CmsSearchConfiguration(org.opencms.jsp.search.config.I_CmsSearchConfiguration) I_CmsSearchController(org.opencms.jsp.search.controller.I_CmsSearchController) CmsResource(org.opencms.file.CmsResource) CmsSolrIndex(org.opencms.search.solr.CmsSolrIndex) CmsSolrQuery(org.opencms.search.solr.CmsSolrQuery) I_CmsSearchConfiguration(org.opencms.jsp.search.config.I_CmsSearchConfiguration) CmsSearchConfiguration(org.opencms.jsp.search.config.CmsSearchConfiguration) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList) ListConfigurationBean(org.opencms.ui.apps.lists.CmsListManager.ListConfigurationBean) HashSet(java.util.HashSet)

Example 5 with CmsSolrResultList

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;
}
Also used : CmsSearchController(org.opencms.jsp.search.controller.CmsSearchController) CmsObject(org.opencms.file.CmsObject) CmsResource(org.opencms.file.CmsResource) I_CmsSearchConfigurationCommon(org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon) CmsSolrIndex(org.opencms.search.solr.CmsSolrIndex) ArrayList(java.util.ArrayList) CmsSearchException(org.opencms.search.CmsSearchException) CmsSolrQuery(org.opencms.search.solr.CmsSolrQuery) CmsSearchConfiguration(org.opencms.jsp.search.config.CmsSearchConfiguration) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList)

Aggregations

CmsSolrResultList (org.opencms.search.solr.CmsSolrResultList)13 CmsSolrQuery (org.opencms.search.solr.CmsSolrQuery)11 CmsSolrIndex (org.opencms.search.solr.CmsSolrIndex)9 CmsSearchException (org.opencms.search.CmsSearchException)7 CmsResource (org.opencms.file.CmsResource)6 CmsObject (org.opencms.file.CmsObject)4 CmsSearchConfiguration (org.opencms.jsp.search.config.CmsSearchConfiguration)4 CmsSearchController (org.opencms.jsp.search.controller.CmsSearchController)4 CmsSearchResultWrapper (org.opencms.jsp.search.result.CmsSearchResultWrapper)4 HashSet (java.util.HashSet)3 I_CmsSearchConfigurationCommon (org.opencms.jsp.search.config.I_CmsSearchConfigurationCommon)3 I_CmsSearchControllerCommon (org.opencms.jsp.search.controller.I_CmsSearchControllerCommon)3 CmsSearchResource (org.opencms.search.CmsSearchResource)3 ArrayList (java.util.ArrayList)2 I_CmsSearchConfiguration (org.opencms.jsp.search.config.I_CmsSearchConfiguration)2 I_CmsSearchResultWrapper (org.opencms.jsp.search.result.I_CmsSearchResultWrapper)2 ListConfigurationBean (org.opencms.ui.apps.lists.CmsListManager.ListConfigurationBean)2 CmsUUID (org.opencms.util.CmsUUID)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1