Search in sources :

Example 46 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestExternalFeatures method testFeaturesUseStopwordQueryReturnEmptyFeatureVector.

@Test
public void testFeaturesUseStopwordQueryReturnEmptyFeatureVector() throws Exception {
    final SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.add("fl", "*,score,fv:[fv]");
    query.add("rows", "1");
    // Stopword only query passed in
    query.add("rq", "{!ltr reRankDocs=10 model=externalmodel efi.user_query='a' efi.userTitlePhrase1='b' efi.userTitlePhrase2='c'}");
    final String docs0fv_dense_csv = FeatureLoggerTestUtils.toFeatureVector("matchedTitle", "0.0", "titlePhraseMatch", "0.0", "titlePhrasesMatch", "0.0");
    final String docs0fv_sparse_csv = FeatureLoggerTestUtils.toFeatureVector();
    final String docs0fv_default_csv = chooseDefaultFeatureVector(docs0fv_dense_csv, docs0fv_sparse_csv);
    // Features are query title matches, which remove stopwords, leaving blank query, so no matches
    assertJQ("/query" + query.toQueryString(), "/response/docs/[0]/fv=='" + docs0fv_default_csv + "'");
}
Also used : SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 47 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestEmbeddedSolrServerConstructors method testNodeConfigConstructor.

@Test
public void testNodeConfigConstructor() throws Exception {
    Path path = createTempDir();
    SolrResourceLoader loader = new SolrResourceLoader(path);
    NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader).setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString()).build();
    try (EmbeddedSolrServer server = new EmbeddedSolrServer(config, "newcore")) {
        CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
        createRequest.setCoreName("newcore");
        createRequest.setConfigSet("minimal");
        server.request(createRequest);
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("articleid", "test");
        server.add("newcore", doc);
        server.commit();
        assertEquals(1, server.query(new SolrQuery("*:*")).getResults().getNumFound());
        assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound());
    }
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) SolrQuery(org.apache.solr.client.solrj.SolrQuery) NodeConfig(org.apache.solr.core.NodeConfig) Test(org.junit.Test)

Example 48 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class AbstractCloudBackupRestoreTestCase method getShardToDocCountMap.

private Map<String, Integer> getShardToDocCountMap(CloudSolrClient client, DocCollection docCollection) throws SolrServerException, IOException {
    Map<String, Integer> shardToDocCount = new TreeMap<>();
    for (Slice slice : docCollection.getActiveSlices()) {
        String shardName = slice.getName();
        try (HttpSolrClient leaderClient = new HttpSolrClient.Builder(slice.getLeader().getCoreUrl()).withHttpClient(client.getHttpClient()).build()) {
            long docsInShard = leaderClient.query(new SolrQuery("*:*").setParam("distrib", "false")).getResults().getNumFound();
            shardToDocCount.put(shardName, (int) docsInShard);
        }
    }
    return shardToDocCount;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Slice(org.apache.solr.common.cloud.Slice) TreeMap(java.util.TreeMap) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 49 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestTolerantSearch method testGetTopIdsPhaseError.

@SuppressWarnings("unchecked")
public void testGetTopIdsPhaseError() throws SolrServerException, IOException {
    BadResponseWriter.failOnGetTopIds = true;
    BadResponseWriter.failOnGetFields = false;
    SolrQuery query = new SolrQuery();
    query.setQuery("subject:batman OR subject:superman");
    query.addField("id");
    query.addField("subject");
    query.set("distrib", "true");
    query.set("shards", shard1 + "," + shard2);
    query.set(ShardParams.SHARDS_INFO, "true");
    query.set("debug", "true");
    query.set("stats", "true");
    query.set("stats.field", "id");
    query.set("mlt", "true");
    query.set("mlt.fl", "title");
    query.set("mlt.count", "1");
    query.set("mlt.mintf", "0");
    query.set("mlt.mindf", "0");
    query.setHighlight(true);
    query.addFacetField("id");
    query.setFacet(true);
    ignoreException("Dummy exception in BadResponseWriter");
    try {
        collection1.query(query);
        fail("Should get an exception");
    } catch (Exception e) {
    //expected
    }
    query.set(ShardParams.SHARDS_TOLERANT, "true");
    QueryResponse response = collection1.query(query);
    assertTrue(response.getResponseHeader().getBooleanArg(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
    NamedList<Object> shardsInfo = ((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
    boolean foundError = false;
    for (int i = 0; i < shardsInfo.size(); i++) {
        if (shardsInfo.getName(i).contains("collection2")) {
            assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
            foundError = true;
            break;
        }
    }
    assertTrue(foundError);
    assertEquals(1, response.getResults().get(0).getFieldValue("id"));
    assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
    unIgnoreException("Dummy exception in BadResponseWriter");
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException)

Example 50 with SolrQuery

use of org.apache.solr.client.solrj.SolrQuery in project lucene-solr by apache.

the class TestTolerantSearch method testGetFieldsPhaseError.

@SuppressWarnings("unchecked")
public void testGetFieldsPhaseError() throws SolrServerException, IOException {
    BadResponseWriter.failOnGetFields = true;
    BadResponseWriter.failOnGetTopIds = false;
    SolrQuery query = new SolrQuery();
    query.setQuery("subject:batman OR subject:superman");
    query.addField("id");
    query.addField("subject");
    query.set("distrib", "true");
    query.set("shards", shard1 + "," + shard2);
    query.set(ShardParams.SHARDS_INFO, "true");
    query.set("debug", "true");
    query.set("stats", "true");
    query.set("stats.field", "id");
    query.set("mlt", "true");
    query.set("mlt.fl", "title");
    query.set("mlt.count", "1");
    query.set("mlt.mintf", "0");
    query.set("mlt.mindf", "0");
    query.setHighlight(true);
    query.addFacetField("id");
    query.setFacet(true);
    ignoreException("Dummy exception in BadResponseWriter");
    try {
        collection1.query(query);
        fail("Should get an exception");
    } catch (Exception e) {
    //expected
    }
    query.set(ShardParams.SHARDS_TOLERANT, "true");
    QueryResponse response = collection1.query(query);
    assertTrue(response.getResponseHeader().getBooleanArg(SolrQueryResponse.RESPONSE_HEADER_PARTIAL_RESULTS_KEY));
    NamedList<Object> shardsInfo = ((NamedList<Object>) response.getResponse().get(ShardParams.SHARDS_INFO));
    boolean foundError = false;
    for (int i = 0; i < shardsInfo.size(); i++) {
        if (shardsInfo.getName(i).contains("collection2")) {
            assertNotNull(((NamedList<Object>) shardsInfo.getVal(i)).get("error"));
            foundError = true;
            break;
        }
    }
    assertTrue(foundError);
    assertEquals(1, response.getResults().get(0).getFieldValue("id"));
    assertEquals("batman", response.getResults().get(0).getFirstValue("subject"));
    unIgnoreException("Dummy exception in BadResponseWriter");
}
Also used : QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException)

Aggregations

SolrQuery (org.apache.solr.client.solrj.SolrQuery)327 Test (org.junit.Test)174 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)129 SolrServerException (org.apache.solr.client.solrj.SolrServerException)53 SolrInputDocument (org.apache.solr.common.SolrInputDocument)52 SolrDocument (org.apache.solr.common.SolrDocument)47 ArrayList (java.util.ArrayList)46 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)45 IOException (java.io.IOException)36 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)33 SolrDocumentList (org.apache.solr.common.SolrDocumentList)33 SolrClient (org.apache.solr.client.solrj.SolrClient)27 LinearModel (org.apache.solr.ltr.model.LinearModel)24 Map (java.util.Map)23 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)23 Replica (org.apache.solr.common.cloud.Replica)23 Slice (org.apache.solr.common.cloud.Slice)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 SolrException (org.apache.solr.common.SolrException)18