Search in sources :

Example 6 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class RealTimeGetComponent method processGetVersions.

///////////////////////////////////////////////////////////////////////////////////
// Returns last versions added to index
///////////////////////////////////////////////////////////////////////////////////
public void processGetVersions(ResponseBuilder rb) throws IOException {
    SolrQueryRequest req = rb.req;
    SolrQueryResponse rsp = rb.rsp;
    SolrParams params = req.getParams();
    if (!params.getBool(COMPONENT_NAME, true)) {
        return;
    }
    int nVersions = params.getInt("getVersions", -1);
    if (nVersions == -1)
        return;
    boolean doFingerprint = params.getBool("fingerprint", false);
    String sync = params.get("sync");
    if (sync != null) {
        processSync(rb, nVersions, sync);
        return;
    }
    UpdateLog ulog = req.getCore().getUpdateHandler().getUpdateLog();
    if (ulog == null)
        return;
    // and would avoid mismatch if documents are being actively index especially during PeerSync
    if (doFingerprint) {
        IndexFingerprint fingerprint = IndexFingerprint.getFingerprint(req.getCore(), Long.MAX_VALUE);
        rb.rsp.add("fingerprint", fingerprint);
    }
    try (UpdateLog.RecentUpdates recentUpdates = ulog.getRecentUpdates()) {
        List<Long> versions = recentUpdates.getVersions(nVersions);
        rb.rsp.add("versions", versions);
    }
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) IndexFingerprint(org.apache.solr.update.IndexFingerprint) UpdateLog(org.apache.solr.update.UpdateLog) AtomicLong(java.util.concurrent.atomic.AtomicLong) SolrParams(org.apache.solr.common.params.SolrParams) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) IndexFingerprint(org.apache.solr.update.IndexFingerprint)

Example 7 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class RealTimeGetComponent method addDocListToResponse.

/**
   * Encapsulates logic for how a {@link SolrDocumentList} should be added to the response
   * based on the request params used
   */
private void addDocListToResponse(final ResponseBuilder rb, final SolrDocumentList docList) {
    assert null != docList;
    final SolrQueryResponse rsp = rb.rsp;
    final IdsRequsted reqIds = IdsRequsted.parseParams(rb.req);
    if (reqIds.useSingleDocResponse) {
        assert docList.size() <= 1;
        // if the doc was not found, then use a value of null.
        rsp.add("doc", docList.size() > 0 ? docList.get(0) : null);
    } else {
        docList.setNumFound(docList.size());
        rsp.addResponse(docList);
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse)

Example 8 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class ClusteringComponentTest method testComponent.

@Test
public void testComponent() throws Exception {
    SolrCore core = h.getCore();
    SearchComponent sc = core.getSearchComponent("clustering");
    assertTrue("sc is null and it shouldn't be", sc != null);
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add(ClusteringComponent.COMPONENT_NAME, "true");
    params.add(CommonParams.Q, "*:*");
    params.add(ClusteringParams.USE_SEARCH_RESULTS, "true");
    SolrRequestHandler handler = core.getRequestHandler("standard");
    SolrQueryResponse rsp;
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap<>());
    SolrQueryRequest req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    NamedList<?> values = rsp.getValues();
    Object clusters = values.get("clusters");
    //System.out.println("Clusters: " + clusters);
    assertTrue("clusters is null and it shouldn't be", clusters != null);
    req.close();
    params = new ModifiableSolrParams();
    params.add(ClusteringComponent.COMPONENT_NAME, "true");
    params.add(ClusteringParams.ENGINE_NAME, "mock");
    params.add(ClusteringParams.USE_COLLECTION, "true");
    params.add(QueryComponent.COMPONENT_NAME, "false");
    handler = core.getRequestHandler("docClustering");
    rsp = new SolrQueryResponse();
    rsp.addResponseHeader(new SimpleOrderedMap<>());
    req = new LocalSolrQueryRequest(core, params);
    handler.handleRequest(req, rsp);
    values = rsp.getValues();
    clusters = values.get("clusters");
    //System.out.println("Clusters: " + clusters);
    assertTrue("clusters is null and it shouldn't be", clusters != null);
    req.close();
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) SearchComponent(org.apache.solr.handler.component.SearchComponent) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrRequestHandler(org.apache.solr.request.SolrRequestHandler) Test(org.junit.Test)

Example 9 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class ManagedFeatureStore method doGet.

/**
   * Called to retrieve a named part (the given childId) of the resource at the
   * given endpoint. Note: since we have a unique child feature store we ignore
   * the childId.
   */
@Override
public void doGet(BaseSolrResource endpoint, String childId) {
    final SolrQueryResponse response = endpoint.getSolrResponse();
    // If no feature store specified, show all the feature stores available
    if (childId == null) {
        response.add(FEATURE_STORE_JSON_FIELD, stores.keySet());
    } else {
        final FeatureStore store = getFeatureStore(childId);
        if (store == null) {
            throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "missing feature store [" + childId + "]");
        }
        response.add(FEATURES_JSON_FIELD, featuresAsManagedResources(store));
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) FeatureStore(org.apache.solr.ltr.store.FeatureStore) SolrException(org.apache.solr.common.SolrException)

Example 10 with SolrQueryResponse

use of org.apache.solr.response.SolrQueryResponse in project lucene-solr by apache.

the class UpdateRequestHandlerApi method getApiImpl.

private Api getApiImpl() {
    return new Api(ApiBag.getSpec("core.Update")) {

        @Override
        public void call(SolrQueryRequest req, SolrQueryResponse rsp) {
            String path = req.getPath();
            String target = mapping.get(path);
            if (target != null)
                req.getContext().put("path", target);
            try {
                handleRequest(req, rsp);
            } catch (RuntimeException e) {
                throw e;
            } catch (Exception e) {
                throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
            }
        }
    };
}
Also used : SolrQueryRequest(org.apache.solr.request.SolrQueryRequest) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) Api(org.apache.solr.api.Api) SolrException(org.apache.solr.common.SolrException) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)258 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)128 Test (org.junit.Test)100 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)80 NamedList (org.apache.solr.common.util.NamedList)68 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)58 SolrCore (org.apache.solr.core.SolrCore)52 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 SolrInputDocument (org.apache.solr.common.SolrInputDocument)40 SolrException (org.apache.solr.common.SolrException)32 ContentStreamBase (org.apache.solr.common.util.ContentStreamBase)29 ArrayList (java.util.ArrayList)26 BufferingRequestProcessor (org.apache.solr.update.processor.BufferingRequestProcessor)24 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)22 SolrRequestInfo (org.apache.solr.request.SolrRequestInfo)21 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)20 UpdateRequestProcessor (org.apache.solr.update.processor.UpdateRequestProcessor)20 JsonLoader (org.apache.solr.handler.loader.JsonLoader)17 IOException (java.io.IOException)16 HashMap (java.util.HashMap)16