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