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