Search in sources :

Example 1 with IndexFieldType

use of org.broadleafcommerce.core.search.domain.IndexFieldType in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldDaoImpl method getIndexFieldTypesByAbbreviationAndEntityType.

@Override
public List<IndexFieldType> getIndexFieldTypesByAbbreviationAndEntityType(String abbreviation, FieldEntity entityType) {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<IndexFieldType> criteria = builder.createQuery(IndexFieldType.class);
    Root<IndexFieldTypeImpl> root = criteria.from(IndexFieldTypeImpl.class);
    criteria.select(root);
    if (entityType == null) {
        criteria.where(builder.equal(root.get("indexField").get("field").get("abbreviation").as(String.class), abbreviation));
    } else {
        criteria.where(builder.and(builder.equal(root.get("indexField").get("field").get("abbreviation").as(String.class), abbreviation), builder.equal(root.get("indexField").get("field").get("entityType").as(String.class), entityType.getType())));
    }
    TypedQuery<IndexFieldType> query = em.createQuery(criteria);
    query.setHint(QueryHints.HINT_CACHEABLE, true);
    query.setHint(QueryHints.HINT_CACHE_REGION, "query.Search");
    return query.getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl)

Example 2 with IndexFieldType

use of org.broadleafcommerce.core.search.domain.IndexFieldType in project BroadleafCommerce by BroadleafCommerce.

the class IndexFieldCustomPersistenceHandler method getEntity.

protected Entity getEntity(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity, Map<String, FieldMetadata> adminProperties, IndexField adminInstance) throws ServiceException {
    adminInstance = (IndexField) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
    adminInstance = dynamicEntityDao.merge(adminInstance);
    ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
    if (extensionManager != null) {
        result = extensionManager.getProxy().addtoSearchableFields(persistencePackage, adminInstance);
    }
    if (result.equals(ExtensionResultStatusType.NOT_HANDLED)) {
        // If there is no searchable field types then we need to add a default as String
        if (CollectionUtils.isEmpty(adminInstance.getFieldTypes())) {
            IndexFieldType indexFieldType = new IndexFieldTypeImpl();
            indexFieldType.setFieldType(FieldType.TEXT);
            indexFieldType.setIndexField(adminInstance);
            adminInstance.getFieldTypes().add(indexFieldType);
            adminInstance = dynamicEntityDao.merge(adminInstance);
        }
    }
    Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
    return adminEntity;
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) Entity(org.broadleafcommerce.openadmin.dto.Entity) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 3 with IndexFieldType

use of org.broadleafcommerce.core.search.domain.IndexFieldType in project BroadleafCommerce by BroadleafCommerce.

the class SolrSearchServiceImpl method getQueryFields.

/**
 * This helper method gathers the query fields for the given field and stores them in the List parameter.
 * @param currentField the current field
 * @param query
 * @param queryFields the query fields for this query
 * @param searchCriteria
 */
protected void getQueryFields(SolrQuery query, final List<String> queryFields, IndexField indexField, SearchCriteria searchCriteria) {
    if (indexField != null && BooleanUtils.isTrue(indexField.getSearchable())) {
        List<IndexFieldType> fieldTypes = indexField.getFieldTypes();
        for (IndexFieldType indexFieldType : fieldTypes) {
            FieldType fieldType = indexFieldType.getFieldType();
            // this will hold the list of query fields for our given field
            ExtensionResultHolder<List<String>> queryFieldResult = new ExtensionResultHolder<>();
            queryFieldResult.setResult(queryFields);
            // here we try to get the query field's for this search field
            ExtensionResultStatusType result = extensionManager.getProxy().getQueryField(query, searchCriteria, indexFieldType, queryFieldResult);
            if (Objects.equals(ExtensionResultStatusType.NOT_HANDLED, result)) {
                // if we didn't get any query fields we just add a default one
                String solrFieldName = shs.getPropertyNameForIndexField(indexFieldType.getIndexField(), fieldType);
                queryFields.add(solrFieldName);
            }
        }
    }
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) List(java.util.List) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) FieldType(org.broadleafcommerce.core.search.domain.solr.FieldType)

Example 4 with IndexFieldType

use of org.broadleafcommerce.core.search.domain.IndexFieldType in project BroadleafCommerce by BroadleafCommerce.

the class MvelToSearchCriteriaConversionServiceImpl method buildCustomFieldQuery.

protected String buildCustomFieldQuery(String customFieldPropertyName, String customFieldValue) {
    String customFieldQuery;
    List<IndexFieldType> indexFieldTypes = indexFieldDao.getIndexFieldTypesByAbbreviationOrPropertyName(customFieldPropertyName);
    if (isCustomFieldIndexed(indexFieldTypes)) {
        customFieldQuery = "*:*&fq=(";
        for (IndexFieldType indexFieldType : indexFieldTypes) {
            String type = indexFieldType.getFieldType().getType();
            String indexFieldName = customFieldPropertyName + "_" + type;
            String indexFieldValue = "\"" + customFieldValue + "\"";
            if (!isFirstItem(customFieldQuery)) {
                customFieldQuery += " OR ";
            }
            customFieldQuery += indexFieldName + ":" + indexFieldValue;
        }
        customFieldQuery += ")";
    } else {
        customFieldQuery = "";
        LOG.warn("The " + customFieldPropertyName + " Custom Field must be indexed with Solr in order " + "to gather results based on an MVEL rule.");
    }
    return customFieldQuery;
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType)

Example 5 with IndexFieldType

use of org.broadleafcommerce.core.search.domain.IndexFieldType in project BroadleafCommerce by BroadleafCommerce.

the class SolrIndexServiceImpl method attachIndexableDocumentFields.

@Override
public void attachIndexableDocumentFields(SolrInputDocument document, Indexable indexable, List<IndexField> fields, List<Locale> locales) {
    for (IndexField indexField : fields) {
        try {
            // If we find an IndexField entry for this field, then we need to store it in the index
            if (indexField != null) {
                List<IndexFieldType> searchableFieldTypes = indexField.getFieldTypes();
                // For each of its search field types, get the property values, and add a field to the document for each property value
                for (IndexFieldType sft : searchableFieldTypes) {
                    FieldType fieldType = sft.getFieldType();
                    Map<String, Object> propertyValues = getPropertyValues(indexable, indexField.getField(), fieldType, locales);
                    ExtensionResultStatusType result = extensionManager.getProxy().populateDocumentForIndexField(document, indexField, fieldType, propertyValues);
                    if (ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
                        // Build out the field for every prefix
                        for (Entry<String, Object> entry : propertyValues.entrySet()) {
                            String prefix = entry.getKey();
                            prefix = StringUtils.isBlank(prefix) ? prefix : prefix + "_";
                            String solrPropertyName = shs.getPropertyNameForIndexField(indexField, fieldType, prefix);
                            Object value = entry.getValue();
                            if (FieldType.isMultiValued(fieldType)) {
                                document.addField(solrPropertyName, value);
                            } else {
                                document.setField(solrPropertyName, value);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Could not get value for property[" + indexField.getField().getQualifiedFieldName() + "] for product id[" + indexable.getId() + "]", e);
            throw ExceptionHelper.refineException(e);
        }
    }
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) IndexField(org.broadleafcommerce.core.search.domain.IndexField) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) FieldType(org.broadleafcommerce.core.search.domain.solr.FieldType)

Aggregations

IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)8 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)4 IndexFieldTypeImpl (org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl)4 ArrayList (java.util.ArrayList)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 FieldType (org.broadleafcommerce.core.search.domain.solr.FieldType)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 List (java.util.List)1 Predicate (javax.persistence.criteria.Predicate)1 ORDER (org.apache.solr.client.solrj.SolrQuery.ORDER)1 SortClause (org.apache.solr.client.solrj.SolrQuery.SortClause)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 IndexField (org.broadleafcommerce.core.search.domain.IndexField)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1