Search in sources :

Example 56 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrHelperServiceImpl method getCategoryId.

@Override
public Long getCategoryId(Category category) {
    Long[] returnId = new Long[1];
    ExtensionResultStatusType result = searchExtensionManager.getProxy().getCategoryId(category, returnId);
    if (result.equals(ExtensionResultStatusType.HANDLED)) {
        return returnId[0];
    }
    return category.getId();
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 57 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrHelperServiceImpl method attachSortClause.

@Override
public void attachSortClause(SolrQuery query, SearchCriteria searchCriteria, String defaultSort) {
    String sortQuery = searchCriteria.getSortQuery();
    if (StringUtils.isBlank(sortQuery)) {
        sortQuery = defaultSort;
    }
    if (StringUtils.isNotBlank(sortQuery)) {
        String[] sortFields = sortQuery.split(",");
        List<String> sortableFieldTypes = getSortableFieldTypes();
        for (String sortField : sortFields) {
            String[] sortFieldsSegments = sortField.split(" ");
            String requestedSortFieldName = sortFieldsSegments[0];
            ORDER order = getSortOrder(sortFieldsSegments, sortQuery);
            ExtensionResultStatusType result = searchExtensionManager.getProxy().attachSortField(query, requestedSortFieldName, order);
            if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
                // if an index field was not found, or the extension handler handled attaching the sort field, move to the next field
                continue;
            }
            List<IndexFieldType> fieldTypes = indexFieldDao.getIndexFieldTypesByAbbreviation(requestedSortFieldName);
            // Used to determine if, by looping through the index field types managed in the database, we actually
            // attach the sort field that is being requested. If we do, then we shouldn't manually add the requested
            // sort field ourselves but if not, we should
            boolean requestedSortFieldAdded = false;
            // and some not  give a preference to NOT tokenized fields, and remove tokenized.
            // In case you have tokenized only just add them all
            List<SortClause> sortClauses = new ArrayList<>();
            boolean foundNotTokenizedField = false;
            // this sorts by them all
            for (IndexFieldType fieldType : fieldTypes) {
                String field = getPropertyNameForIndexField(fieldType.getIndexField(), fieldType.getFieldType());
                // be checked
                if (fieldType.getIndexField().getField().getAbbreviation().equals(requestedSortFieldName)) {
                    requestedSortFieldAdded = true;
                }
                SortClause sortClause = new SortClause(field, order);
                if (sortableFieldTypes.contains(fieldType.getFieldType().getType())) {
                    if (!sortClauses.isEmpty() && !foundNotTokenizedField) {
                        sortClauses.clear();
                    }
                    sortClauses.add(sortClause);
                    foundNotTokenizedField = true;
                } else if (!foundNotTokenizedField) {
                    sortClauses.add(sortClause);
                }
            }
            if (!foundNotTokenizedField) {
                LOG.warn(String.format("Sorting on a tokenized field, this could have adverse effects on the ordering of results. " + "Add a field type for this field from the following list to ensure proper result ordering: [%s]", StringUtils.join(sortableFieldTypes, ", ")));
            }
            if (!sortClauses.isEmpty()) {
                for (SortClause sortClause : sortClauses) {
                    query.addSort(sortClause);
                }
            }
            // field anyway since we're trusting that the field was actually added to the index by some programmatic means
            if (!requestedSortFieldAdded) {
                query.addSort(new SortClause(requestedSortFieldName, order));
            }
        }
    }
}
Also used : ORDER(org.apache.solr.client.solrj.SolrQuery.ORDER) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) SortClause(org.apache.solr.client.solrj.SolrQuery.SortClause) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 58 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrHelperServiceImpl method getIndexableId.

@Override
public Long getIndexableId(Indexable indexable) {
    Long[] returnId = new Long[1];
    ExtensionResultStatusType result = indexExtensionManager.getProxy().getIndexableId(indexable, returnId);
    if (result.equals(ExtensionResultStatusType.HANDLED)) {
        return returnId[0];
    }
    return indexable.getId();
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 59 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class SolrSearchServiceImpl method getCategoryFacets.

@Override
public List<SearchFacetDTO> getCategoryFacets(Category category) {
    List<SearchFacet> searchFacets = new ArrayList<>();
    ExtensionResultStatusType status = extensionManager.getProxy().getCategorySearchFacets(category, searchFacets);
    if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, status)) {
        List<CategorySearchFacet> categorySearchFacets = category.getCumulativeSearchFacets();
        for (CategorySearchFacet categorySearchFacet : categorySearchFacets) {
            searchFacets.add(categorySearchFacet.getSearchFacet());
        }
    }
    return buildSearchFacetDTOs(searchFacets);
}
Also used : CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) SearchFacet(org.broadleafcommerce.core.search.domain.SearchFacet) CategorySearchFacet(org.broadleafcommerce.core.search.domain.CategorySearchFacet) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Aggregations

ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)59 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)9 Category (org.broadleafcommerce.core.catalog.domain.Category)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)7 ServiceException (org.broadleafcommerce.common.exception.ServiceException)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)6 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Query (javax.persistence.Query)4 TypedQuery (javax.persistence.TypedQuery)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)4 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)4 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3