Example usage for org.apache.solr.request SolrRequestInfo getReq

List of usage examples for org.apache.solr.request SolrRequestInfo getReq

Introduction

In this page you can find the example usage for org.apache.solr.request SolrRequestInfo getReq.

Prototype

public SolrQueryRequest getReq() 

Source Link

Usage

From source file:org.vootoo.schema.CrossCoreField.java

License:Apache License

@Override
public ValueSource getValueSource(SchemaField field, QParser parser) {
    SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
    if (info == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "Cross-core field [" + field.getName() + "] must have SolrRequestInfo");
    }/*from   w w w .  j  av  a  2 s.c  o m*/

    String[] crossCore = dumpCrossSchemaField(field);

    SchemaField uniqueKeyField = schema.getUniqueKeyField();

    final SolrCore targetCore = info.getReq().getCore().getCoreDescriptor().getCoreContainer()
            .getCore(crossCore[0]);
    if (targetCore == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
                "Cross-core field [" + field.getName() + "] miss target core [" + crossCore[0] + "]");
    }

    SchemaField targetField = targetCore.getLatestSchema().getFieldOrNull(crossCore[1]);
    if (targetField == null) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core field [" + field.getName()
                + "] core [" + crossCore[0] + "] miss field [" + crossCore[1] + "]");
    }

    final RefCounted<SolrIndexSearcher> targetCoreSearcher = targetCore.getSearcher();
    SolrIndexSearcher targetSolrIndexSearcher = targetCoreSearcher.get();

    CrossCoreFieldValueSource ccfvs = new CrossCoreFieldValueSource(uniqueKeyField, targetField, parser,
            targetSolrIndexSearcher);

    info.addCloseHook(new Closeable() {
        @Override
        public void close() throws IOException {
            targetCoreSearcher.decref();
            targetCore.close();
        }
    });

    return ccfvs;
}