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());
}
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);
}
}
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;
}
Aggregations