org.apache.solr.client.solrj.request.LukeRequest Java Examples

The following examples show how to use org.apache.solr.client.solrj.request.LukeRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicCopyFieldsIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Map<String, HashSet<String>> getIndexedFieldsModifiers() throws IOException, SolrServerException {
    SolrClient solrClient = getStandaloneClients().get(0);
    LukeRequest request = new LukeRequest();
    LukeResponse response = request.process(solrClient);
    Map<String, HashSet<String>> collect = response.getFieldInfo().keySet().stream()
            .map(k -> k.split("@|\\{|\\}"))
            .filter(e -> e.length == 5)
            .collect(Collectors.toMap(
                    a -> a[4],
                    a -> Sets.newHashSet(a[1]),
                    (value1, value2) -> {
                        value1.addAll(value2);
                        return value1;
                    }));
    return collect;
}
 
Example #2
Source File: TestSolrConfigHandlerCloud.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testAdminPath() throws Exception{
  String testServerBaseUrl = getRandomServer(cloudClient,"collection1");
  RestTestHarness writeHarness = randomRestTestHarness();
  String payload = "{\n" +
      "'create-requesthandler' : { 'name' : '/admin/luke', " +
      "'class': 'org.apache.solr.handler.DumpRequestHandler'}}";

  TestSolrConfigHandler.runConfigCommand(writeHarness, "/config", payload);


  TestSolrConfigHandler.testForResponseElement(writeHarness,
      testServerBaseUrl,
      "/config/overlay",
      cloudClient,
      Arrays.asList("overlay", "requestHandler", "/admin/luke", "class"),
      "org.apache.solr.handler.DumpRequestHandler",
      TIMEOUT_S);

 NamedList<Object> rsp = cloudClient.request(new LukeRequest());
 System.out.println(rsp);
}
 
Example #3
Source File: SolrColumnMetadataDao.java    From metron with Apache License 2.0 6 votes vote down vote up
protected List<Map<String, Object>> getIndexFields(String index)
    throws IOException, SolrServerException {
  List<Map<String, Object>> indexFields = new ArrayList<>();

  // Get all the fields in use, including dynamic fields
  LukeRequest lukeRequest = new LukeRequest();
  LukeResponse lukeResponse = lukeRequest.process(client, index);
  for (Entry<String, LukeResponse.FieldInfo> field : lukeResponse.getFieldInfo().entrySet()) {
    Map<String, Object> fieldData = new HashMap<>();
    fieldData.put("name", field.getValue().getName());
    fieldData.put("type", field.getValue().getType());
    indexFields.add(fieldData);

  }

  // Get all the schema fields
  SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index)
      .getSchemaRepresentation();
  indexFields.addAll(schemaRepresentation.getFields());

  return indexFields;
}
 
Example #4
Source File: SolrExampleTests.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testLukeHandler() throws Exception
 {    
   SolrClient client = getSolrClient();
   
   // Empty the database...
   client.deleteByQuery("*:*");// delete everything!
   
   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();
   assertNumFound( "*:*", doc.length ); // make sure it got in
   
   LukeRequest luke = new LukeRequest();
   luke.setShowSchema( false );
   LukeResponse rsp = luke.process( client );
   assertNull( rsp.getFieldTypeInfo() ); // if you don't ask for it, the schema is null
   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() );
 }
 
Example #5
Source File: SolrSchema.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Map<String, LukeResponse.FieldInfo> getFieldInfo(String collection) {
  String zk = this.properties.getProperty("zk");
  CloudSolrClient cloudSolrClient = solrClientCache.getCloudSolrClient(zk);
  try {
    LukeRequest lukeRequest = new LukeRequest();
    lukeRequest.setNumTerms(0);
    LukeResponse lukeResponse = lukeRequest.process(cloudSolrClient, collection);
    return lukeResponse.getFieldInfo();
  } catch (SolrServerException | IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #6
Source File: DistribCursorPagingTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  @SuppressWarnings({"unchecked"})
  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);
}
 
Example #7
Source File: SolrSearchEngine.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<String> getDynamicFieldNames() throws SearchEngineException {
	List<String> fields = new ArrayList<>();
	
	LukeRequest request = new LukeRequest();
	request.setNumTerms(0);
	request.setShowSchema(false);
	try {
		LukeResponse response = request.process(getServer());
		NamedList<Object> flds = (NamedList<Object>) response.getResponse().get("fields");
		if (flds != null) {
			for (Map.Entry<String, Object> field : flds) {
				String name = field.getKey();
				for (Entry<String, Object> prop : (NamedList<Object>)field.getValue()) {
					if ("dynamicBase".equals(prop.getKey())) {
						fields.add(name);
						break;
					}
				}
			}
		}

	} catch (SolrServerException | IOException e) {
		throw new SearchEngineException(e);
	}
	
	return fields;
}