本文整理汇总了Java中org.apache.solr.client.solrj.request.CoreAdminRequest.Create方法的典型用法代码示例。如果您正苦于以下问题:Java CoreAdminRequest.Create方法的具体用法?Java CoreAdminRequest.Create怎么用?Java CoreAdminRequest.Create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.client.solrj.request.CoreAdminRequest
的用法示例。
在下文中一共展示了CoreAdminRequest.Create方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndex
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
public void createIndex() throws SolrServerException, IOException, NdexException {
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet(
"ndex-nodes");
// "data_driven_schema_configs");
CoreAdminResponse foo = creator.process(client);
if ( foo.getStatus() != 0 ) {
throw new NdexException ("Failed to create solrIndex for network " + coreName + ". Error: " + foo.getResponseHeader().toString());
}
counter = 0;
docs = new ArrayList<>(batchSize);
client.setBaseURL(solrUrl + "/" + coreName);
}
示例2: create
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
/**
* @param solrHome the Solr home directory to use
* @param configSetHome the directory containing config sets
* @param coreName the name of the core, must have a matching directory in configHome
* @param cleanSolrHome if true the directory for solrHome will be deleted and re-created if it already exists
* @return an EmbeddedSolrServer with a core created for the given coreName
*/
public static SolrClient create(final String solrHome, final String configSetHome, final String coreName, final boolean cleanSolrHome)
throws IOException, SolrServerException {
final File solrHomeDir = new File(solrHome);
if (solrHomeDir.exists()) {
FileUtils.deleteDirectory(solrHomeDir);
solrHomeDir.mkdirs();
} else {
solrHomeDir.mkdirs();
}
final SolrResourceLoader loader = new SolrResourceLoader(solrHomeDir.toPath());
final Path configSetPath = Paths.get(configSetHome).toAbsolutePath();
final NodeConfig config = new NodeConfig.NodeConfigBuilder("embeddedSolrServerNode", loader)
.setConfigSetBaseDirectory(configSetPath.toString())
.build();
final EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(config, coreName);
final CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
createRequest.setCoreName(coreName);
createRequest.setConfigSet(coreName);
embeddedSolrServer.request(createRequest);
return embeddedSolrServer;
}
示例3: createThings
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
@BeforeClass
public static void createThings() throws Exception {
solrHome = createSolrHome();
createJetty(solrHome.getAbsolutePath(), null, null);
String url = jetty.getBaseUrl().toString();
collection1 = new HttpSolrServer(url);
collection2 = new HttpSolrServer(url + "/collection2");
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
shard1 = urlCollection1.replaceAll("https?://", "");
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
collection1.request(req);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
doc.setField("text", "batman");
collection1.add(doc);
collection1.commit();
doc.setField("id", "2");
doc.setField("text", "superman");
collection2.add(doc);
collection2.commit();
}
示例4: createThings
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
@BeforeClass
public static void createThings() throws Exception {
solrHome = createSolrHome();
createJetty(solrHome.getAbsolutePath(), null, null);
String url = jetty.getBaseUrl().toString();
collection1 = new HttpSolrServer(url);
collection2 = new HttpSolrServer(url + "/collection2");
String urlCollection1 = jetty.getBaseUrl().toString() + "/" + "collection1";
String urlCollection2 = jetty.getBaseUrl().toString() + "/" + "collection2";
shard1 = urlCollection1.replaceAll("https?://", "");
shard2 = urlCollection2.replaceAll("https?://", "");
//create second core
CoreAdminRequest.Create req = new CoreAdminRequest.Create();
req.setCoreName("collection2");
collection1.request(req);
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "1");
doc.setField("subject", "batman");
doc.setField("title", "foo bar");
collection1.add(doc);
collection1.commit();
doc.setField("id", "2");
doc.setField("subject", "superman");
collection2.add(doc);
collection2.commit();
doc = new SolrInputDocument();
doc.setField("id", "3");
doc.setField("subject", "aquaman");
doc.setField("title", "foo bar");
collection1.add(doc);
collection1.commit();
}
示例5: rebuildUserIndex
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
private static void rebuildUserIndex() throws Exception {
logger.info("Start rebuild user index.");
try(UserIndexManager umgr = new UserIndexManager()) {
String coreName = UserIndexManager.coreName;
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet( coreName);
CoreAdminResponse foo = creator.process(umgr.client);
if ( foo.getStatus() != 0 ) {
throw new NdexException ("Failed to create solrIndex for " + coreName + ". Error: " + foo.getResponseHeader().toString());
}
logger.info("Solr core " + coreName + " created.");
try (UserDAO dao = new UserDAO ()) {
@SuppressWarnings("resource")
Connection db = dao.getDBConnection();
String sqlStr = "select \"UUID\" from ndex_user n where n.is_deleted=false and n.is_verified=true";
try (PreparedStatement pst = db.prepareStatement(sqlStr)) {
try ( ResultSet rs = pst.executeQuery()) {
while (rs.next()) {
UUID userId = (UUID)rs.getObject(1);
try (UserDAO dao2 = new UserDAO()) {
User user = dao2.getUserById(userId, true, false);
if (user == null)
throw new NdexException ("User " + userId+ " can't be indexed because this account is not verified.");
logger.info("Adding user " + user.getUserName() + " to index.");
umgr.addUser(user.getExternalId().toString(), user.getUserName(), user.getFirstName(),
user.getLastName(), user.getDisplayName(), user.getDescription());
logger.info("User " + user.getUserName() + " added to index.");
}
}
}
}
}
}
logger.info("User index has been rebuilt.");
}
示例6: createCoreIfNotExists
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
public void createCoreIfNotExists() throws SolrServerException, IOException, NdexException {
CoreAdminResponse foo = CoreAdminRequest.getStatus(coreName,client);
if (foo.getStatus() != 0 ) {
throw new NdexException ("Failed to get status of solrIndex for " + coreName + ". Error: " + foo.getResponseHeader().toString());
}
NamedList<Object> bar = foo.getResponse();
NamedList<Object> st = (NamedList<Object>)bar.get("status");
NamedList<Object> core = (NamedList<Object>)st.get(coreName);
if ( core.size() == 0 ) {
System.out.println("Solr core " + coreName + " doesn't exist. Creating it now ....");
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet( coreName);
foo = creator.process(client);
if ( foo.getStatus() != 0 ) {
throw new NdexException ("Failed to create solrIndex for " + coreName + ". Error: " + foo.getResponseHeader().toString());
}
System.out.println("Done.");
}
else {
System.out.println("Found core "+ coreName + " in Solr.");
}
}
示例7: createCoreIfNotExists
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
public void createCoreIfNotExists() throws SolrServerException, IOException, NdexException {
CoreAdminResponse foo = CoreAdminRequest.getStatus(coreName,client);
if (foo.getStatus() != 0 ) {
throw new NdexException ("Failed to get status of solrIndex for " + coreName + ". Error: " + foo.getResponseHeader().toString());
}
NamedList<Object> bar = foo.getResponse();
NamedList<Object> st = (NamedList<Object>)bar.get("status");
NamedList<Object> core = (NamedList<Object>)st.get(coreName);
if ( core.size() == 0 ) {
System.out.println("Solr core " + coreName + " doesn't exist. Creating it now ....");
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet( coreName);
foo = creator.process(client);
if ( foo.getStatus() != 0 ) {
throw new NdexException ("Failed to create solrIndex for network " + coreName + ". Error: " + foo.getResponseHeader().toString());
}
System.out.println("Done.");
}
else {
System.out.println("Found core "+ coreName + " in Solr.");
}
}
示例8: rebuildGroupIndex
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
private static void rebuildGroupIndex() throws Exception {
logger.info("Start rebuild group index.");
try (GroupIndexManager umgr = new GroupIndexManager()) {
String coreName = GroupIndexManager.coreName;
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet(coreName);
CoreAdminResponse foo = creator.process(umgr.client);
if (foo.getStatus() != 0) {
throw new NdexException("Failed to create solrIndex for " + coreName + ". Error: "
+ foo.getResponseHeader().toString());
}
logger.info("Solr core " + coreName + " created.");
try (GroupDAO dao = new GroupDAO()) {
@SuppressWarnings("resource")
Connection db = dao.getDBConnection();
String sqlStr = "select \"UUID\" from ndex_group n where n.is_deleted=false";
try (PreparedStatement pst = db.prepareStatement(sqlStr)) {
try (ResultSet rs = pst.executeQuery()) {
while (rs.next()) {
UUID groupId = (UUID) rs.getObject(1);
try (GroupDAO dao2 = new GroupDAO()) {
Group group = dao2.getGroupById(groupId);
if (group == null)
throw new NdexException("Group " + groupId
+ " can't be indexed because this account is not verified.");
logger.info("Adding Group " + group.getGroupName() + " to index.");
umgr.addGroup(group.getExternalId().toString(), group.getGroupName(),
group.getDescription());
logger.info("Group " + group.getGroupName() + " added to index.");
}
}
}
}
}
logger.info("Group index has been rebuilt.");
}
}
示例9: createIndex
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
public void createIndex(Set<String> extraIndexFields) throws SolrServerException, IOException, NdexException {
if ( extraIndexFields == null) {
createDefaultIndex();
return;
}
//create a configSet from template first.
ConfigSetAdminRequest.Create confSetCreator = new ConfigSetAdminRequest.Create();
confSetCreator.setBaseConfigSetName("ndex-nodes-template");
confSetCreator.setConfigSetName(collectionName);
ConfigSetAdminResponse cr = confSetCreator.process(client);
if ( cr.getStatus() != 0 ) {
throw new NdexException("Failed to create Solr ConfigSet " + collectionName);
}
//CollectionAdminRequest.Create creator = CollectionAdminRequest.createCollection(collectionName,"ndex-nodes",1 , 1);
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(collectionName);
creator.setConfigSet(
collectionName);
creator.setIsLoadOnStartup(Boolean.FALSE);
creator.setIsTransient(Boolean.TRUE);
// "data_driven_schema_configs");
CoreAdminResponse foo = creator.process(client);
if ( foo.getStatus() != 0 ) {
throw new NdexException ("Failed to create solrIndex for network " + collectionName + ". Error: " + foo.getResponseHeader().toString());
}
client.setBaseURL(solrUrl + "/" + collectionName);
//extend the schema
/* if ( extraIndexFields !=null ) {
for (String fieldName: extraIndexFields ) {
Map<String, Object> fieldAttributes = new LinkedHashMap<>();
fieldAttributes.put("name", fieldName);
fieldAttributes.put("type", "text_ws");
fieldAttributes.put("stored", false);
fieldAttributes.put("required", false);
SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributes);
SchemaResponse.UpdateResponse addFieldResponse = addFieldUpdateSchemaRequest.process(client);
System.out.println(addFieldResponse.getStatus());
}
}
SchemaRequest.Fields fieldsSchemaRequest = new SchemaRequest.Fields();
SchemaResponse.FieldsResponse currentFieldsResponse = fieldsSchemaRequest.process(client);
List<Map<String, Object>> currentFields = currentFieldsResponse.getFields();
System.out.println(currentFields);
*/
counter = 0;
docs = new ArrayList<>(batchSize);
Map<Long,NodeIndexEntry> tab = createIndexDocs();
for ( NodeIndexEntry e : tab.values()) {
addNodeIndex(e.getId(), e.getName(),e.getRepresents() ,e.getAliases());
}
commit();
}
示例10: createDefaultIndex
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
private void createDefaultIndex() throws SolrServerException, IOException, NdexException {
//CollectionAdminRequest.Create creator = CollectionAdminRequest.createCollection(collectionName,"ndex-nodes",1 , 1);
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(collectionName);
creator.setConfigSet(
"ndex-nodes");
creator.setIsLoadOnStartup(Boolean.FALSE);
creator.setIsTransient(Boolean.TRUE);
// "data_driven_schema_configs");
CoreAdminResponse foo = creator.process(client);
if ( foo.getStatus() != 0 ) {
throw new NdexException ("Failed to create solrIndex for network " + collectionName + ". Error: " + foo.getResponseHeader().toString());
}
client.setBaseURL(solrUrl + "/" + collectionName);
//extend the schema
/* if ( extraIndexFields !=null ) {
for (String fieldName: extraIndexFields ) {
Map<String, Object> fieldAttributes = new LinkedHashMap<>();
fieldAttributes.put("name", fieldName);
fieldAttributes.put("type", "text_ws");
fieldAttributes.put("stored", false);
fieldAttributes.put("required", false);
SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributes);
SchemaResponse.UpdateResponse addFieldResponse = addFieldUpdateSchemaRequest.process(client);
System.out.println(addFieldResponse.getStatus());
}
}
SchemaRequest.Fields fieldsSchemaRequest = new SchemaRequest.Fields();
SchemaResponse.FieldsResponse currentFieldsResponse = fieldsSchemaRequest.process(client);
List<Map<String, Object>> currentFields = currentFieldsResponse.getFields();
System.out.println(currentFields);
*/
counter = 0;
docs = new ArrayList<>(batchSize);
Map<Long,NodeIndexEntry> tab = createIndexDocs();
for ( NodeIndexEntry e : tab.values()) {
addNodeIndex(e.getId(), e.getName(),e.getRepresents() ,e.getAliases());
}
commit();
}
示例11: test0
import org.apache.solr.client.solrj.request.CoreAdminRequest; //导入方法依赖的package包/类
@Test
public void test0() throws SolrServerException, IOException {
String solrUrl = "http://localhost:8983/solr/";
String coreName = "test12";
HttpSolrClient client = new HttpSolrClient(solrUrl);
// ConcurrentUpdateSolrServer solrServer = new ConcurrentUpdateSolrServer(solrUrl, 1,2);
// CoreAdminResponse foo = CoreAdminRequest.createCore(coreName, "test1", client, ""
// );
CoreAdminRequest.Create creator = new CoreAdminRequest.Create();
creator.setCoreName(coreName);
creator.setConfigSet("data_driven_schema_configs");
creator.process(client);
String baseURL = client.getBaseURL();
System.out.println("base url:"+ baseURL);
client.setBaseURL(solrUrl+ coreName);
Collection<SolrInputDocument> docs = new ArrayList<>();
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField("id", 12 );
doc1.addField("n", "XXBC");
doc1.addField("r", "HGNC:MK1");
doc1.addField("r", "MK1");
doc1.addField("a", "MKX");
doc1.addField("a", "MK2");
docs.add(doc1);
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField("id", 22 );
doc2.addField("n", "protein");
doc2.addField("r", "UniProt:Q6FGS5");
doc2.addField("r", "Q6FGS5");
doc2.addField("a", "Ensembl:ENSP00000254661");
doc2.addField("a", "ENSP00000254661");
doc2.addField("a", "HGNC Symbol:RAMP1");
doc2.addField("a", "RAMP1");
docs.add(doc2);
client.add(docs);
client.commit();
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("protein").setFields("id");
QueryResponse rsp = client.query(solrQuery);
SolrDocumentList dds = rsp.getResults();
for ( SolrDocument d : dds) {
System.out.println(d.get("id"));
}
client.setBaseURL(baseURL);
// foo = CoreAdminRequest.unloadCore(coreName, client);
// System.out.println(foo);
}