Search in sources :

Example 1 with LukeResponse

use of org.apache.solr.client.solrj.response.LukeResponse 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 LukeResponse

use of org.apache.solr.client.solrj.response.LukeResponse 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 3 with LukeResponse

use of org.apache.solr.client.solrj.response.LukeResponse 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)

Aggregations

LukeRequest (org.apache.solr.client.solrj.request.LukeRequest)3 LukeResponse (org.apache.solr.client.solrj.response.LukeResponse)3 IOException (java.io.IOException)2 SolrServerException (org.apache.solr.client.solrj.SolrServerException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ErrorTrackingConcurrentUpdateSolrClient (org.apache.solr.client.solrj.embedded.SolrExampleStreamingTest.ErrorTrackingConcurrentUpdateSolrClient)1 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)1 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)1 FieldInfo (org.apache.solr.client.solrj.response.LukeResponse.FieldInfo)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Test (org.junit.Test)1