Search in sources :

Example 1 with SpecialFieldEnum

use of org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum in project stanbol by apache.

the class SolrFieldMapper method getFieldNames.

@Override
public List<String> getFieldNames(IndexField indexField) throws IllegalArgumentException {
    if (indexField == null) {
        throw new IllegalArgumentException("The parsed IndexField name MUST NOT be NULL!");
    }
    List<String> fieldNames = indexFieldMappings.get(indexField);
    if (fieldNames == null) {
        // check for special field;
        SpecialFieldEnum specialField = indexField.getSpecialField();
        if (specialField != null) {
            switch(specialField) {
                case fullText:
                    fieldNames = Collections.singletonList(getFullTextSearchField());
                    break;
                case references:
                    fieldNames = Collections.singletonList(getReferredDocumentField());
                    break;
                default:
                    throw new IllegalStateException("Unsupported Special Field '" + specialField.getUri() + "! Please report this to the " + "Stanbol Developer Mailing list or create an according" + "JIRA issue at https://issues.apache.org/jira/browse/STANBOL!");
            }
        } else {
            // typically only 1 or 2 values
            fieldNames = new ArrayList<String>(2);
            IndexDataTypeEnum dataTypeConfig = IndexDataTypeEnum.forIndexType(indexField.getDataType());
            if (dataTypeConfig == null) {
                throw new IllegalStateException(String.format("No Config found for the parsed IndexDataType %s", indexField.getDataType()));
            }
            // Three things need to be done
            // 1) Encode the Path
            String pathName = encodePathName(indexField);
            // 2) Encode the DataType
            fieldNames.addAll(encodeDataType(pathName, dataTypeConfig));
            // 3) Encode the Languages
            if (indexField.hasLanguage()) {
                fieldNames.addAll(encodeLanguages(pathName, indexField.getLanguages()));
            }
            // language texts)
            if (dataTypeConfig.isLanguageType()) {
                fieldNames.add(SolrConst.LANG_MERGER_FIELD + pathName);
            }
        }
        // cache the mappings
        indexFieldMappings.put(indexField, fieldNames);
    }
    return fieldNames;
}
Also used : SpecialFieldEnum(org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum) IndexDataTypeEnum(org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum)

Example 2 with SpecialFieldEnum

use of org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum in project stanbol by apache.

the class SolrFieldMapper method encodePathName.

/**
 * Getter for the string used to index a the parsed path. This method replaces the URI's of all elements
 * within the path with <code>prefix+NAMESPACE_PREFIX_SEPERATOR_CHAR+localName</code>. In addition it
 * places the <code>PATH_SEPERATOR</code> char between the elements.
 * <p>
 * NOTES: <ul>
 *  <li>This Method assumes that no empty or <code>null</code> elements are
 *  containted in the parsed list.
 *  <li>This Method supports special encoding of fields registered in the
 *  {@link SpecialFieldEnum}. However those fields are only allowed to be
 *  used in paths with the length <code>1</code>.
 *  An {@link IllegalArgumentException} is thrown if a special field is used
 *  in a longer path.
 * </ul>
 * @param path
 *            the path to encode
 * @return the path name
 * @throws IllegalArgumentException if <code>null</code> or an empty list is
 * parsed as path or a special field is used in a path with a length &gt; 1
 * @throws IllegalStateException if an unknown {@link SpecialFieldEnum
 * special field} is encountered.
 */
private String encodePathName(IndexField indexField) {
    SpecialFieldEnum specialField = indexField.getSpecialField();
    if (specialField != null) {
        // handel special fields
        switch(specialField) {
            case fullText:
                return getFullTextSearchField();
            case references:
                return getReferredDocumentField();
            default:
                throw new IllegalStateException("Unsupported Special Field '" + specialField.getUri() + "'! Please report this to" + "the Apache Stanbol Developer Mailing List!");
        }
    } else {
        // normal field
        StringBuilder pathName = new StringBuilder();
        // Now Iterate over the Path
        // add the leading PathSeperator
        pathName.append(PATH_SEPERATOR);
        Iterator<String> fields = indexField.getPath().iterator();
        while (fields.hasNext()) {
            String field = fields.next();
            String[] namespaceLocalName = ModelUtils.getNamespaceLocalName(field);
            // QName qName = getQName(field);
            if (namespaceLocalName[0] != null && !namespaceLocalName[0].isEmpty()) {
                pathName.append(getPrefix(namespaceLocalName[0], true));
                // second the local name
                pathName.append(NAMESPACE_PREFIX_SEPERATOR_CHAR);
            }
            pathName.append(namespaceLocalName[1]);
            // third add Path Separator if there are additional Elements
            if (fields.hasNext()) {
                pathName.append(PATH_SEPERATOR);
            }
        }
        // add the tailing PathSeperator
        pathName.append(PATH_SEPERATOR);
        return pathName.toString();
    }
}
Also used : SpecialFieldEnum(org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum)

Aggregations

SpecialFieldEnum (org.apache.stanbol.entityhub.servicesapi.defaults.SpecialFieldEnum)2 IndexDataTypeEnum (org.apache.stanbol.entityhub.yard.solr.defaults.IndexDataTypeEnum)1