Search in sources :

Example 1 with SpanQueryBuilder

use of org.apache.lucene.queryparser.xml.builders.SpanQueryBuilder in project lucene-solr by apache.

the class SolrCoreParser method init.

@Override
public void init(NamedList initArgs) {
    if (initArgs == null || initArgs.size() == 0) {
        return;
    }
    final SolrResourceLoader loader;
    if (req == null) {
        loader = new SolrResourceLoader();
    } else {
        loader = req.getCore().getResourceLoader();
    }
    final Iterable<Map.Entry<String, Object>> args = initArgs;
    for (final Map.Entry<String, Object> entry : args) {
        final String queryName = entry.getKey();
        final String queryBuilderClassName = (String) entry.getValue();
        try {
            final SolrSpanQueryBuilder spanQueryBuilder = loader.newInstance(queryBuilderClassName, SolrSpanQueryBuilder.class, null, new Class[] { String.class, Analyzer.class, SolrQueryRequest.class, SpanQueryBuilder.class }, new Object[] { defaultField, analyzer, req, this });
            this.addSpanQueryBuilder(queryName, spanQueryBuilder);
        } catch (Exception outerException) {
            try {
                final SolrQueryBuilder queryBuilder = loader.newInstance(queryBuilderClassName, SolrQueryBuilder.class, null, new Class[] { String.class, Analyzer.class, SolrQueryRequest.class, QueryBuilder.class }, new Object[] { defaultField, analyzer, req, this });
                this.addQueryBuilder(queryName, queryBuilder);
            } catch (Exception innerException) {
                log.error("Class {} not found or not suitable: {} {}", queryBuilderClassName, outerException, innerException);
                throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Cannot find suitable " + SolrSpanQueryBuilder.class.getCanonicalName() + " or " + SolrQueryBuilder.class.getCanonicalName() + " class: " + queryBuilderClassName + " in " + loader);
            }
        }
    }
}
Also used : SpanQueryBuilder(org.apache.lucene.queryparser.xml.builders.SpanQueryBuilder) QueryBuilder(org.apache.lucene.queryparser.xml.QueryBuilder) Analyzer(org.apache.lucene.analysis.Analyzer) SolrException(org.apache.solr.common.SolrException) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) Map(java.util.Map) SolrException(org.apache.solr.common.SolrException)

Aggregations

Map (java.util.Map)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 QueryBuilder (org.apache.lucene.queryparser.xml.QueryBuilder)1 SpanQueryBuilder (org.apache.lucene.queryparser.xml.builders.SpanQueryBuilder)1 SolrException (org.apache.solr.common.SolrException)1 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1