Package org.apache.stanbol.entityhub.yard.solr.model

Examples of org.apache.stanbol.entityhub.yard.solr.model.IndexValue


                // constraint per query

                List<String> fields = new ArrayList<String>();
                fields.add(fieldConstraint.getKey());
                SimilarityConstraint simConstraint = (SimilarityConstraint) fieldConstraint.getValue();
                IndexValue indexValue = indexValueFactory.createIndexValue(simConstraint.getContext());
                fields.addAll(simConstraint.getAdditionalFields());
                if(!similarityConstraintPresent){
                    similarityConstraintPresent = true; //similarity constraint present
                    //add the constraint to the query
                    query.setQueryType(MLT_QUERY_TYPE);
                    query.set(MATCH_INCLUDE, false);
                    query.set(MIN_DOC_FREQ, 1);
                    query.set(MIN_TERM_FREQ, 1);
                    query.set(INTERESTING_TERMS, "details");
                    query.set("mlt.boost", true); //testing
                    List<String> indexFields = new ArrayList<String>();
                    for(String field : fields){
                        IndexField indexField = new IndexField(Collections.singletonList(field),
                            IndexDataTypeEnum.TXT.getIndexType());
                        indexFields.addAll(fieldMapper.getFieldNames(indexField));
                    }
                    query.set(SIMILARITY_FIELDS, indexFields.toArray(new String[fields.size()]));
                    query.set(STREAM_BODY, indexValue.getValue());
                    processedFieldConstraints.put(fieldConstraint.getKey(), fieldConstraint.getValue());
                } else { //similarity constraint already present -> ignore further
                    //NOTE: users are informed about that by NOT including further
                    //      similarity constraints in the query included in the
                    //      response
View Full Code Here


                    }
                }
            } //else empty we will initialise based on the first parsed value!
            ConstraintValue constraintValue = new ConstraintValue(valueConstraint.getMode());
            for(Object value : valueConstraint.getValues()){
                IndexValue indexValue;
                if(indexDataType == null){ // if no supported types are present
                    // get the dataType based on the type of the value
                    try {
                        indexValue = indexValueFactory.createIndexValue(value);
                    } catch (NoConverterException e) {
                        // if not found use the toString() and string as type
                        log.warn("Unable to create IndexValue for value {} (type: {}). Create IndexValue manually by using the first parsed IndexDataType {}",
                                    new Object[]{
                                        value, value.getClass(),
                                        IndexDataTypeEnum.STR.getIndexType()
                                    });
                        indexValue = new IndexValue(value.toString(),
                            IndexDataTypeEnum.STR.getIndexType());
                    }
                    //initialise the IndexDataType for this query based on the first parsed value
                    indexDataType = indexValue.getType();
                } else {
                    indexValue = new IndexValue(value.toString(), indexDataType);
                }
                constraintValue.getValues().add(indexValue); //add the constraint
            }
            //indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.DATATYPE, indexDataType);
            IndexField indexField;
View Full Code Here

    }

    @Override
    public void encode(EncodedConstraintParts constraint, Object value) {
        Double boost = null;
        IndexValue indexValue;
        if (value == null) {
            indexValue = null; // default value
        } else if (value instanceof IndexValue) {
            indexValue = (IndexValue) value;
        } else if (value instanceof ConstraintValue){
            ConstraintValue cv = (ConstraintValue) value;
            indexValue = cv.getValues() == null || cv.getValues().isEmpty() ? null :
                cv.getValues().iterator().next();
            boost = cv.getBoost();
        } else {
            indexValue = indexValueFactory.createIndexValue(value);
        }
        StringBuilder ltConstraint = new StringBuilder("TO ");
        if(indexValue != null && indexValue.getValue() != null
                && !indexValue.getValue().isEmpty()){
            ltConstraint.append(indexValue.getValue());
        } else {
            ltConstraint.append(DEFAULT);
        }
        ltConstraint.append('}');
        if(boost != null){
View Full Code Here

        this.indexValueFactory = indexValueFactory;
    }

    @Override
    public void encode(EncodedConstraintParts constraint, Object value) {
        IndexValue indexValue;
        if (value == null) {
            indexValue = null; // default value
        } else if (value instanceof IndexValue) {
            indexValue = (IndexValue) value;
        } else if (value instanceof ConstraintValue){
            ConstraintValue cv = (ConstraintValue) value;
            indexValue = cv.getValues() == null || cv.getValues().isEmpty() ? null :
                cv.getValues().iterator().next();
        } else {
            indexValue = indexValueFactory.createIndexValue(value);
        }
        String geConstraint = String
                .format("[%s ", indexValue != null && indexValue.getValue() != null
                                && !indexValue.getValue().isEmpty() ? indexValue.getValue() : DEFAULT);
        constraint.addEncoded(POS, geConstraint);
    }
View Full Code Here

        this.indexValueFactory = indexValueFactory;
    }

    @Override
    public void encode(EncodedConstraintParts constraint, Object value) {
        IndexValue indexValue;
        Double boost = null;
        if (value == null) {
            indexValue = null; // default value
        } else if (value instanceof IndexValue) {
            indexValue = (IndexValue) value;
        } else if (value instanceof ConstraintValue){
            ConstraintValue cv = (ConstraintValue) value;
            indexValue = cv.getValues() == null || cv.getValues().isEmpty() ? null :
                cv.getValues().iterator().next();
            boost = cv.getBoost();
        } else {
            indexValue = indexValueFactory.createIndexValue(value);
        }
        StringBuilder leConstraint = new StringBuilder("TO ");
        if(indexValue != null && indexValue.getValue() != null
                && !indexValue.getValue().isEmpty()){
            leConstraint.append(indexValue.getValue());
        } else {
            leConstraint.append(DEFAULT);
        }
        leConstraint.append(']');
        if(boost != null){
View Full Code Here

        this.indexValueFactory = indexValueFactory;
    }

    @Override
    public void encode(EncodedConstraintParts constraint, Object value) {
        IndexValue indexValue;
        if (value == null) {
            indexValue = null; // default value
        } else if (value instanceof IndexValue) {
            indexValue = (IndexValue) value;
        } else if (value instanceof ConstraintValue){
            ConstraintValue cv = (ConstraintValue) value;
            indexValue = cv.getValues() == null || cv.getValues().isEmpty() ? null :
                cv.getValues().iterator().next();
        } else {
            indexValue = indexValueFactory.createIndexValue(value);
        }
        String geConstraint = String.format("{%s ",
            indexValue != null && indexValue.getValue() != null
                    && !indexValue.getValue().toString().isEmpty() ? indexValue.getValue() : DEFAULT);
        constraint.addEncoded(POS, geConstraint);
    }
View Full Code Here

                // constraint per query

                List<String> fields = new ArrayList<String>();
                fields.add(fieldConstraint.getKey());
                SimilarityConstraint simConstraint = (SimilarityConstraint) fieldConstraint.getValue();
                final IndexValue contextValue =
                        indexValueFactory.createIndexValue(simConstraint.getContext());
                fields.addAll(simConstraint.getAdditionalFields());
                if(!similarityConstraintPresent){
                    similarityConstraintPresent = true; //similarity constraint present
                    //add the constraint to the query
                    query.setRequestHandler(MLT_QUERY_TYPE);
                    query.set(MATCH_INCLUDE, false);
                    query.set(MIN_DOC_FREQ, 1);
                    query.set(MIN_TERM_FREQ, 1);
                    query.set(INTERESTING_TERMS, "details");
                    query.set("mlt.boost", true); //testing
                    List<String> indexFields = new ArrayList<String>();
                    for(String field : fields){
                        //we need to get the actual fields in the index for the
                        //logical fields parsed with the constraint
                        IndexDataTypeEnum mapedIndexTypeEnum = IndexDataTypeEnum.forDataTyoe(simConstraint.getContextType());
                        IndexField indexField = new IndexField(Collections.singletonList(field),
                            mapedIndexTypeEnum == null ? null : mapedIndexTypeEnum.getIndexType(),
                            simConstraint.getLanguages());
                        indexFields.addAll(fieldMapper.getQueryFieldNames(indexField));
                    }
                    query.set(SIMILARITY_FIELDS, indexFields.toArray(new String[fields.size()]));
                    query.set(STREAM_BODY, contextValue.getValue());
                    processedFieldConstraints.put(fieldConstraint.getKey(), fieldConstraint.getValue());
                } else { //similarity constraint already present -> ignore further
                    //NOTE: users are informed about that by NOT including further
                    //      similarity constraints in the query included in the
                    //      response
View Full Code Here

        //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(
View Full Code Here

                }
            } //else empty we will initialise based on the first parsed value!
            ConstraintValue constraintValue = new ConstraintValue(valueConstraint.getMode());
            addBoost(constraintValue, valueConstraint); //init the boost
            for(Object value : valueConstraint.getValues()){
                IndexValue indexValue;
                if(indexDataType == null){ // if no supported types are present
                    // get the dataType based on the type of the value
                    try {
                        indexValue = indexValueFactory.createIndexValue(value);
                    } catch (NoConverterException e) {
                        // if not found use the toString() and string as type
                        log.warn("Unable to create IndexValue for value {} (type: {}). Create IndexValue manually by using the first parsed IndexDataType {}",
                                    new Object[]{
                                        value, value.getClass(),
                                        IndexDataTypeEnum.STR.getIndexType()
                                    });
                        indexValue = new IndexValue(value.toString(),
                            IndexDataTypeEnum.STR.getIndexType());
                    }
                    //initialise the IndexDataType for this query based on the first parsed value
                    indexDataType = indexValue.getType();
                } else {
                    indexValue = new IndexValue(value.toString(), indexDataType);
                }
                constraintValue.getValues().add(indexValue); //add the constraint
            }
            //indexConstraint.setFieldConstraint(IndexConstraintTypeEnum.DATATYPE, indexDataType);
            IndexField indexField;
View Full Code Here

            //  Holding field values in an own map does not make sense as the SolrInputDocument
            //  does already exactly that (in an more efficient way)
            for (Iterator<Object> values = representation.get(field); values.hasNext();) {
                // now we need to get the indexField for the value
                Object next = values.next();
                IndexValue value;
                try {
                    value = indexValueFactory.createIndexValue(next);
                    for (String fieldName : fieldMapper.getFieldNames(Arrays.asList(field), value)) {
                        //In step (1) of boosting just keep track of the field
                        if(fieldBoost != null){ //wee need to boost in (2)
                            int[] numValues = fieldsToBoost.get(fieldName);
                            if(numValues == null){
                                numValues = new int[]{1};
                                fieldsToBoost.put(fieldName, numValues);
                                //the first time add the document with the baseBoost
                                //as this will be the correct boost for single value fields
                                inputDocument.addField(fieldName, value.getValue(),baseBoost);
                            } else {
                                numValues[0]++;
                                //for multi valued fields the correct boost is set in (2)
                                //so we can add here without an boost
                                inputDocument.addField(fieldName, value.getValue());
                            }
                        } else {
                            //add add the values without boost
                            inputDocument.addField(fieldName, value.getValue());
                        }
                    }
                } catch (NoConverterException e) {
                    log.warn(
                        String.format("Unable to convert value %s (type:%s) for field %s!", next,
View Full Code Here

TOP

Related Classes of org.apache.stanbol.entityhub.yard.solr.model.IndexValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.