Search in sources :

Example 1 with SolrField

use of com.odysseusinc.arachne.portal.service.impl.solr.SolrField in project ArachneCentralAPI by OHDSI.

the class BaseSolrServiceImpl method getValuesByEntity.

@Override
public Map<T, Object> getValuesByEntity(final SolrEntity entity) {
    final Map<T, Object> values = new HashMap<>();
    final FieldList<T> fieldList = getFieldsOfClass(entity.getClass());
    for (final T solrField : fieldList) {
        final Object fieldValue;
        final Field field = solrField.getField();
        final SolrFieldExtractor extractor = solrField.getExtractor();
        if (extractor != null) {
            fieldValue = extractor.extract(entity);
        } else if (field != null) {
            field.setAccessible(true);
            fieldValue = getFieldValue(entity, field);
        } else {
            throw new NullPointerException("FieldValue cannot be null");
        }
        values.put(solrField, fieldValue);
    }
    if (entity.getId() != null) {
        final T idField = newSolrField(ID);
        idField.setDataType(Long.class);
        idField.setPostfixNeeded(false);
        values.put(idField, entity.getId());
    }
    addBreadcrumbsIfNeeded(entity, values);
    return values;
}
Also used : SolrField(com.odysseusinc.arachne.portal.service.impl.solr.SolrField) Field(java.lang.reflect.Field) HashMap(java.util.HashMap) SolrFieldExtractor(com.odysseusinc.arachne.portal.api.v1.dto.converters.SolrFieldExtractor)

Example 2 with SolrField

use of com.odysseusinc.arachne.portal.service.impl.solr.SolrField in project ArachneCentralAPI by OHDSI.

the class BaseSolrServiceImpl method getFieldsOfClass.

public FieldList<T> getFieldsOfClass(final Class<?> entity) {
    final FieldList<T> result = new FieldList<>();
    final List<Field> fields = getDeclaredFields(entity);
    for (final Field field : fields) {
        final T solrField = getSolrField(field);
        if (solrField != null) {
            result.add(solrField);
        }
    }
    result.addAll(gatherClassSolrAnnotations(entity));
    return result;
}
Also used : SolrField(com.odysseusinc.arachne.portal.service.impl.solr.SolrField) Field(java.lang.reflect.Field) FieldList(com.odysseusinc.arachne.portal.service.impl.solr.FieldList)

Example 3 with SolrField

use of com.odysseusinc.arachne.portal.service.impl.solr.SolrField in project ArachneCentralAPI by OHDSI.

the class SearchDTOToSolrQuery method setSorting.

protected void setSorting(SearchDTO source, SolrQuery result, FieldList solrFields) {
    if (source.getSort() != null && source.getOrder() != null) {
        // Check if such field exists in Solr index and retrieve it
        SolrField sortSolrSolrField = solrFields.getByName(source.getSort());
        if (sortSolrSolrField != null) {
            String sortFieldName = sortSolrSolrField.isMultiValuesType() ? sortSolrSolrField.getMultiValuesTypeFieldName() : sortSolrSolrField.getSolrName();
            result.setSort(sortFieldName, SolrQuery.ORDER.valueOf(source.getOrder()));
        }
    }
}
Also used : SolrField(com.odysseusinc.arachne.portal.service.impl.solr.SolrField)

Example 4 with SolrField

use of com.odysseusinc.arachne.portal.service.impl.solr.SolrField in project ArachneCentralAPI by OHDSI.

the class SearchDTOToSolrQuery method setFilters.

protected void setFilters(SearchDTO source, SolrQuery result, FieldList solrFields) {
    Map<String, Object> filterInput = source.getFilter();
    if (filterInput != null) {
        for (Map.Entry<String, Object> filterEntry : filterInput.entrySet()) {
            String filterName = filterEntry.getKey();
            Object filterValue = filterEntry.getValue();
            SolrField solrField = solrFields.getByName(filterName);
            if (solrField != null && solrField.getFaceted()) {
                result.addFilterQuery(getExcludedTag(solrField.getSolrName()) + solrField.getSolrName() + ":" + filterValue);
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) Map(java.util.Map) SolrField(com.odysseusinc.arachne.portal.service.impl.solr.SolrField)

Aggregations

SolrField (com.odysseusinc.arachne.portal.service.impl.solr.SolrField)4 Field (java.lang.reflect.Field)2 SolrFieldExtractor (com.odysseusinc.arachne.portal.api.v1.dto.converters.SolrFieldExtractor)1 FieldList (com.odysseusinc.arachne.portal.service.impl.solr.FieldList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1