Search in sources :

Example 6 with ScoreMode

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

the class ScoreJoinQParserPlugin 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 {
            final String fromField = localParams.get("from");
            final String fromIndex = localParams.get("fromIndex");
            final String toField = localParams.get("to");
            final ScoreMode scoreMode = ScoreModeParser.parse(getParam(SCORE));
            final String v = localParams.get(CommonParams.VALUE);
            final Query q = createQuery(fromField, v, fromIndex, toField, scoreMode, CommonParams.TRUE.equals(localParams.get("TESTenforceSameCoreAsAnotherOne")));
            return q;
        }

        private Query createQuery(final String fromField, final String fromQueryStr, String fromIndex, final String toField, final ScoreMode scoreMode, boolean byPassShortCircutCheck) throws SyntaxError {
            final String myCore = req.getCore().getCoreDescriptor().getName();
            if (fromIndex != null && (!fromIndex.equals(myCore) || byPassShortCircutCheck)) {
                CoreContainer container = req.getCore().getCoreContainer();
                final String coreName = getCoreName(fromIndex, container);
                final SolrCore fromCore = container.getCore(coreName);
                RefCounted<SolrIndexSearcher> fromHolder = null;
                if (fromCore == null) {
                    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Cross-core join: no such core " + coreName);
                }
                long fromCoreOpenTime = 0;
                LocalSolrQueryRequest otherReq = new LocalSolrQueryRequest(fromCore, params);
                try {
                    QParser fromQueryParser = QParser.getParser(fromQueryStr, otherReq);
                    Query fromQuery = fromQueryParser.getQuery();
                    fromHolder = fromCore.getRegisteredSearcher();
                    if (fromHolder != null) {
                        fromCoreOpenTime = fromHolder.get().getOpenNanoTime();
                    }
                    return new OtherCoreJoinQuery(fromQuery, fromField, coreName, fromCoreOpenTime, scoreMode, toField);
                } finally {
                    otherReq.close();
                    fromCore.close();
                    if (fromHolder != null)
                        fromHolder.decref();
                }
            } else {
                QParser fromQueryParser = subQuery(fromQueryStr, null);
                final Query fromQuery = fromQueryParser.getQuery();
                return new SameCoreJoinQuery(fromQuery, fromField, toField, scoreMode);
            }
        }
    };
}
Also used : ScoreMode(org.apache.lucene.search.join.ScoreMode) Query(org.apache.lucene.search.Query) SolrCore(org.apache.solr.core.SolrCore) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) CoreContainer(org.apache.solr.core.CoreContainer) QParser(org.apache.solr.search.QParser) SolrException(org.apache.solr.common.SolrException)

Aggregations

ScoreMode (org.apache.lucene.search.join.ScoreMode)6 Query (org.apache.lucene.search.Query)2 ParsingException (org.elasticsearch.common.ParsingException)2 XContentParser (org.elasticsearch.common.xcontent.XContentParser)2 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 BoostQuery (org.apache.lucene.search.BoostQuery)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 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)1 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)1 QParser (org.apache.solr.search.QParser)1 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 Ignore (org.junit.Ignore)1