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);
}
}
}
}
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);
}
}
}
Aggregations