Search in sources :

Example 11 with IndexValue

use of org.apache.stanbol.entityhub.yard.solr.model.IndexValue in project stanbol by apache.

the class SolrQueryFactory method initRangeConstraint.

/**
     * @param indexConstraint
     * @param rangeConstraint
     */
private void initRangeConstraint(IndexConstraint indexConstraint) {
    RangeConstraint rangeConstraint = (RangeConstraint) indexConstraint.getConstraint();
    // we need to find the Index DataType for the range query
    IndexDataType dataType = null;
    ConstraintValue lowerBound = new ConstraintValue();
    ConstraintValue upperBound = new ConstraintValue();
    //init the boosts
    addBoost(lowerBound, rangeConstraint);
    addBoost(upperBound, rangeConstraint);
    //init IndexValues and check for the dataType
    if (rangeConstraint.getLowerBound() != null) {
        IndexValue value = indexValueFactory.createIndexValue(rangeConstraint.getLowerBound());
        lowerBound.getValues().add(value);
        dataType = value.getType();
    }
    if (rangeConstraint.getUpperBound() != null) {
        IndexValue value = indexValueFactory.createIndexValue(rangeConstraint.getUpperBound());
        upperBound.getValues().add(value);
        IndexDataType upperDataType = value.getType();
        if (dataType == null) {
            dataType = upperDataType;
        } else {
            if (!dataType.equals(upperDataType)) {
                indexConstraint.setInvalid(String.format("A Range Query MUST use the same data type for the upper " + "and lover Bound! (lower:[value=%s|datatype=%s] | " + "upper:[value=%s|datatype=%s])", rangeConstraint.getLowerBound(), dataType, rangeConstraint.getUpperBound(), upperDataType));
            }
        }
    }
    if (dataType == null) {
        indexConstraint.setInvalid("A Range Constraint MUST define at least a lower or an upper bound!");
    } else {
        //set the DATATYPE and FIED using an IndexField
        indexConstraint.setIndexFieldConstraints(new IndexField(indexConstraint.getPath(), dataType));
    }
    //set the value range
    if (rangeConstraint.isInclusive()) {
        indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.LE, upperBound);
        indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.GE, lowerBound);
    } else {
        indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.LT, upperBound);
        indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.GT, lowerBound);
    }
}
Also used : RangeConstraint(org.apache.stanbol.entityhub.servicesapi.query.RangeConstraint) IndexDataType(org.apache.stanbol.entityhub.yard.solr.model.IndexDataType) IndexValue(org.apache.stanbol.entityhub.yard.solr.model.IndexValue) IndexField(org.apache.stanbol.entityhub.yard.solr.model.IndexField)

Aggregations

IndexValue (org.apache.stanbol.entityhub.yard.solr.model.IndexValue)11 ArrayList (java.util.ArrayList)4 ConstraintValue (org.apache.stanbol.entityhub.yard.solr.impl.SolrQueryFactory.ConstraintValue)4 HashSet (java.util.HashSet)3 IndexField (org.apache.stanbol.entityhub.yard.solr.model.IndexField)3 RangeConstraint (org.apache.stanbol.entityhub.servicesapi.query.RangeConstraint)2 ReferenceConstraint (org.apache.stanbol.entityhub.servicesapi.query.ReferenceConstraint)2 ValueConstraint (org.apache.stanbol.entityhub.servicesapi.query.ValueConstraint)2 IndexDataTypeEnum (org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum)2 IndexDataType (org.apache.stanbol.entityhub.yard.solr.model.IndexDataType)2 NoConverterException (org.apache.stanbol.entityhub.yard.solr.model.NoConverterException)2 QueryTerm (org.apache.stanbol.entityhub.yard.solr.query.QueryUtils.QueryTerm)2 HashMap (java.util.HashMap)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 SolrInputField (org.apache.solr.common.SolrInputField)1 Constraint (org.apache.stanbol.entityhub.servicesapi.query.Constraint)1 SimilarityConstraint (org.apache.stanbol.entityhub.servicesapi.query.SimilarityConstraint)1 TextConstraint (org.apache.stanbol.entityhub.servicesapi.query.TextConstraint)1