Example usage for org.apache.lucene.queryparser.flexible.core.config QueryConfigHandler get

List of usage examples for org.apache.lucene.queryparser.flexible.core.config QueryConfigHandler get

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.core.config QueryConfigHandler get.

Prototype

@SuppressWarnings("unchecked")
public <T> T get(ConfigurationKey<T> key) 

Source Link

Document

Returns the value held by the given key.

Usage

From source file:com.sindicetech.siren.qparser.keyword.processors.DatatypeProcessor.java

License:Open Source License

@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    final QueryConfigHandler conf = this.getQueryConfigHandler();

    // If the current node is a datatype query node, validate the datatype and assign it to its child
    if (node instanceof DatatypeQueryNode) {
        final Map<String, Analyzer> dtAnalyzers = conf.get(KeywordConfigurationKeys.DATATYPES_ANALYZERS);
        final DatatypeQueryNode dt = (DatatypeQueryNode) node;
        String datatype = dt.getDatatype();

        // check if the datatype is correctly registered
        if (dtAnalyzers == null) {
            throw new IllegalArgumentException("KeywordConfigurationKeys.DATAYPES_ANALYZERS "
                    + "should be set on the ExtendedKeywordQueryConfigHandler");
        }//  w  ww  .java2s  . c  o  m
        if (!dtAnalyzers.containsKey(datatype)) {
            throw new IllegalArgumentException("Unknown datatype: [" + datatype + "]");
        }
        if (dtAnalyzers.get(datatype) == null) {
            throw new IllegalArgumentException("Analyzer of datatype [" + datatype + "] cannot be null.");
        }

        // transfer the datatype to its child
        dt.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype);
    }
    // If the current node is a twig query node, assign the json:field datatype to the root, and assign the default
    // or the tagged datatype to the child
    else if (node instanceof TwigQueryNode) {
        final TwigQueryNode twig = (TwigQueryNode) node;
        if (twig.getTag(DatatypeQueryNode.DATATYPE_TAGID) == null) {
            twig.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDefaultDatatype(conf));
        } else {
            twig.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDatatype(conf, node));
        }
        twig.getRoot().setTag(DatatypeQueryNode.DATATYPE_TAGID, JSONDatatype.JSON_FIELD);
    }
    // in any other cases, if the node is not a leaf node, transfer the datatype to its children
    else if (!node.isLeaf()) {
        for (final QueryNode child : node.getChildren()) {
            child.setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDatatype(conf, node));
        }
    }

    return node;
}

From source file:com.sindicetech.siren.qparser.keyword.processors.DatatypeProcessor.java

License:Open Source License

public static String getDefaultDatatype(QueryConfigHandler config) {
    if (config.has(KeywordConfigurationKeys.DEFAULT_DATATYPE)) {
        return config.get(KeywordConfigurationKeys.DEFAULT_DATATYPE);
    } else {/*  w w  w . jav a 2s.c o m*/
        throw new IllegalArgumentException(
                "KeywordConfigurationKeys.DEFAULT_DATATYPE should be set on the ExtendedKeywordQueryConfigHandler");
    }
}

From source file:org.sindice.siren.qparser.keyword.processors.DatatypeQueryNodeProcessor.java

License:Apache License

@Override
protected QueryNode preProcessNode(final QueryNode node) throws QueryNodeException {
    if (node instanceof DatatypeQueryNode) {
        // Set the datatype analyzer to use on the descendant querynodes
        final QueryConfigHandler conf = this.getQueryConfigHandler();
        final Map<String, Analyzer> dtAnalyzers = conf.get(KeywordConfigurationKeys.DATATYPES_ANALYZERS);
        final DatatypeQueryNode dt = (DatatypeQueryNode) node;

        if (dtAnalyzers == null) {
            throw new IllegalArgumentException("KeywordConfigurationKeys.DATAYPES_ANALYZERS "
                    + "should be set on the KeywordQueryConfigHandler");
        }//from w  w  w .j a v  a2s  . c  om
        if (!dtAnalyzers.containsKey(dt.getDatatype())) {
            throw new IllegalArgumentException("Unknown datatype: [" + dt.getDatatype() + "]");
        }
        // check no datatype is already set
        if (datatype != null) {
            throw new IllegalArgumentException("Cannot use more than one datatype in a same tree. " + "Using ["
                    + datatype + "], but receieved also [" + dt.getDatatype() + "]");
        }
        if (dtAnalyzers.get(dt.getDatatype()) == null) {
            throw new IllegalArgumentException("Analyzer of datatype [" + datatype + "] cannot be null.");
        }

        datatype = dt.getDatatype();
    }
    // parent twig query
    else if (node instanceof TwigQueryNode) {
        nbTwigs++;
        if (nbTwigs == 1) {
            // Set the json:field datatype on the top level node only
            final TwigQueryNode twig = (TwigQueryNode) node;
            twig.getRoot().setTag(DatatypeQueryNode.DATATYPE_TAGID, JSONDatatype.JSON_FIELD);
        }
    }
    // A datatype is being used
    else if (datatype != null) {
        node.setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype);
    }
    // Default datatype
    else if (node.getTag(DatatypeQueryNode.DATATYPE_TAGID) == null) {
        node.setTag(DatatypeQueryNode.DATATYPE_TAGID, XSDDatatype.XSD_STRING);
    }
    return node;
}