Search in sources :

Example 1 with ScoreJoinQParserPlugin

use of org.apache.solr.search.join.ScoreJoinQParserPlugin in project lucene-solr by apache.

the class JoinQuery method createParser.

@Override
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {

        @Override
        public Query parse() throws SyntaxError {
            if (localParams != null && localParams.get(ScoreJoinQParserPlugin.SCORE) != null) {
                return new ScoreJoinQParserPlugin().createParser(qstr, localParams, params, req).parse();
            } else {
                return parseJoin();
            }
        }

        Query parseJoin() throws SyntaxError {
            final String fromField = getParam("from");
            final String fromIndex = getParam("fromIndex");
            final String toField = getParam("to");
            final String v = localParams.get("v");
            final String coreName;
            Query fromQuery;
            long fromCoreOpenTime = 0;
            if (fromIndex != null && !fromIndex.equals(req.getCore().getCoreDescriptor().getName())) {
                CoreContainer container = req.getCore().getCoreContainer();
                // if in SolrCloud mode, fromIndex should be the name of a single-sharded collection
                coreName = ScoreJoinQParserPlugin.getCoreName(fromIndex, container);
                final SolrCore fromCore = container.getCore(coreName);
                if (fromCore == null) {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core " + coreName);
                }
                RefCounted<SolrIndexSearcher> fromHolder = null;
                LocalSolrQueryRequest otherReq = new LocalSolrQueryRequest(fromCore, params);
                try {
                    QParser parser = QParser.getParser(v, otherReq);
                    fromQuery = parser.getQuery();
                    fromHolder = fromCore.getRegisteredSearcher();
                    if (fromHolder != null)
                        fromCoreOpenTime = fromHolder.get().getOpenNanoTime();
                } finally {
                    otherReq.close();
                    fromCore.close();
                    if (fromHolder != null)
                        fromHolder.decref();
                }
            } else {
                coreName = null;
                QParser fromQueryParser = subQuery(v, null);
                fromQueryParser.setIsFilter(true);
                fromQuery = fromQueryParser.getQuery();
            }
            JoinQuery jq = new JoinQuery(fromField, toField, coreName == null ? fromIndex : coreName, fromQuery);
            jq.fromCoreOpenTime = fromCoreOpenTime;
            return jq;
        }
    };
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) Query(org.apache.lucene.search.Query) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) ScoreJoinQParserPlugin(org.apache.solr.search.join.ScoreJoinQParserPlugin) SolrException(org.apache.solr.common.SolrException)

Aggregations

Query (org.apache.lucene.search.Query)1 SolrException (org.apache.solr.common.SolrException)1 CoreContainer (org.apache.solr.core.CoreContainer)1 SolrCore (org.apache.solr.core.SolrCore)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 ScoreJoinQParserPlugin (org.apache.solr.search.join.ScoreJoinQParserPlugin)1