Search in sources :

Example 1 with FieldType

use of org.broadleafcommerce.core.search.domain.solr.FieldType 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 2 with FieldType

use of org.broadleafcommerce.core.search.domain.solr.FieldType 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

ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)2 FieldType (org.broadleafcommerce.core.search.domain.solr.FieldType)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)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