Search in sources :

Example 1 with LukeRequest

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

the class SolrExampleTests method testLukeHandler.

@Test
public void testLukeHandler() throws Exception {
    SolrClient client = getSolrClient();
    // Empty the database...
    // delete everything!
    client.deleteByQuery("*:*");
    SolrInputDocument[] doc = new SolrInputDocument[5];
    for (int i = 0; i < doc.length; i++) {
        doc[i] = new SolrInputDocument();
        doc[i].setField("id", "ID" + i);
        client.add(doc[i]);
    }
    client.commit();
    // make sure it got in
    assertNumFound("*:*", doc.length);
    LukeRequest luke = new LukeRequest();
    luke.setShowSchema(false);
    LukeResponse rsp = luke.process(client);
    // if you don't ask for it, the schema is null
    assertNull(rsp.getFieldTypeInfo());
    assertNull(rsp.getDynamicFieldInfo());
    luke.setShowSchema(true);
    rsp = luke.process(client);
    assertNotNull(rsp.getFieldTypeInfo());
    assertNotNull(rsp.getFieldInfo().get("id").getSchemaFlags());
    assertTrue(rsp.getFieldInfo().get("id").getSchemaFlags().contains(FieldFlag.INDEXED));
    assertNotNull(rsp.getDynamicFieldInfo());
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) LukeResponse(org.apache.solr.client.solrj.response.LukeResponse) ErrorTrackingConcurrentUpdateSolrClient(org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Test(org.junit.Test)

Example 2 with LukeRequest

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

the class DistribCursorPagingTest method getAllSortFieldNames.

/**
   * Asks the LukeRequestHandler on the control client for a list of the fields in the 
   * schema and then prunes that list down to just the fields that can be used for sorting,
   * and returns them as an immutable list in a deterministically random order.
   */
private List<String> getAllSortFieldNames() throws SolrServerException, IOException {
    LukeRequest req = new LukeRequest("/admin/luke");
    req.setShowSchema(true);
    NamedList<Object> rsp = controlClient.request(req);
    NamedList<Object> fields = (NamedList) ((NamedList) rsp.get("schema")).get("fields");
    ArrayList<String> names = new ArrayList<>(fields.size());
    for (Map.Entry<String, Object> item : fields) {
        names.add(item.getKey());
    }
    return CursorPagingTest.pruneAndDeterministicallySort(names);
}
Also used : LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 3 with LukeRequest

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

the class SolrSchema method getFieldInfo.

private Map<String, LukeResponse.FieldInfo> getFieldInfo(String collection) {
    String zk = this.properties.getProperty("zk");
    try (CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder().withZkHost(zk).build()) {
        cloudSolrClient.connect();
        LukeRequest lukeRequest = new LukeRequest();
        lukeRequest.setNumTerms(0);
        LukeResponse lukeResponse = lukeRequest.process(cloudSolrClient, collection);
        return lukeResponse.getFieldInfo();
    } catch (SolrServerException | IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) LukeResponse(org.apache.solr.client.solrj.response.LukeResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 4 with LukeRequest

use of org.apache.solr.client.solrj.request.LukeRequest in project ddf by codice.

the class SchemaFieldResolver method getSchemaField.

public SchemaField getSchemaField(String propertyName, boolean isSearchedAsExactValue) {
    SchemaField schemaField = null;
    LukeRequest luke = new LukeRequest();
    LukeResponse rsp;
    try {
        rsp = luke.process(solr);
        Map<String, FieldInfo> fieldsInfo = rsp.getFieldInfo();
        if (fieldsInfo != null && !fieldsInfo.isEmpty()) {
            LOGGER.debug("got fieldsInfo for {} fields", fieldsInfo.size());
            for (Map.Entry<String, FieldInfo> entry : fieldsInfo.entrySet()) {
                // if suffix matches, then get type of field and cache it
                if (entry.getKey().startsWith(propertyName) && StringUtils.endsWithAny(entry.getKey(), FORMAT_SUFFIXES)) {
                    String fieldType = entry.getValue().getType();
                    int index = StringUtils.lastIndexOfAny(entry.getKey(), FORMAT_SUFFIXES);
                    String suffix = entry.getKey().substring(index);
                    if (!isSearchedAsExactValue) {
                        suffix = getSpecialIndexSuffix(suffix);
                        fieldType += suffix;
                    }
                    LOGGER.debug("field {} has type {}", entry.getKey(), fieldType);
                    schemaField = new SchemaField(entry.getKey(), fieldType);
                    schemaField.setSuffix(suffix);
                    return schemaField;
                }
            }
        } else {
            LOGGER.debug("fieldsInfo from LukeRequest are either null or empty");
        }
    } catch (SolrServerException e) {
        LOGGER.info("SolrServerException while processing LukeRequest", e);
    } catch (IOException e) {
        LOGGER.info("IOException while processing LukeRequest", e);
    }
    LOGGER.debug("Did not find SchemaField for property {}", propertyName);
    return schemaField;
}
Also used : LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) LukeResponse(org.apache.solr.client.solrj.response.LukeResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) FieldInfo(org.apache.solr.client.solrj.response.LukeResponse.FieldInfo)

Example 5 with LukeRequest

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

the class TestSolrConfigHandlerCloud method testAdminPath.

private void testAdminPath() throws Exception {
    String testServerBaseUrl = getRandomServer(cloudClient, "collection1");
    RestTestHarness writeHarness = restTestHarnesses.get(random().nextInt(restTestHarnesses.size()));
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/admin/luke', " + "'class': 'org.apache.solr.handler.DumpRequestHandler'}}";
    TestSolrConfigHandler.runConfigCommand(writeHarness, "/config?wt=json", payload);
    TestSolrConfigHandler.testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudClient, Arrays.asList("overlay", "requestHandler", "/admin/luke", "class"), "org.apache.solr.handler.DumpRequestHandler", 10);
    NamedList<Object> rsp = cloudClient.request(new LukeRequest());
    System.out.println(rsp);
}
Also used : LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) RestTestHarness(org.apache.solr.util.RestTestHarness) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString)

Aggregations

LukeRequest (org.apache.solr.client.solrj.request.LukeRequest)6 LukeResponse (org.apache.solr.client.solrj.response.LukeResponse)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)2 NamedList (org.apache.solr.common.util.NamedList)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)1 ErrorTrackingConcurrentUpdateSolrClient (org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient)1 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)1 FieldInfo (org.apache.solr.client.solrj.response.LukeResponse.FieldInfo)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)1