List of usage examples for org.apache.solr.client.solrj.request CoreAdminRequest CoreAdminRequest
public CoreAdminRequest()
From source file:SolrUpdate.java
License:Apache License
public void getAllSolrRecords() { String pmid;//ww w . j av a2 s .c o m try { CoreAdminRequest adminRequest = new CoreAdminRequest(); adminRequest.setAction(CoreAdminAction.RELOAD); SolrServer solr = new HttpSolrServer("http://localhost:8983/solr"); String query; query = "pmid:*"; SolrQuery theq = new SolrQuery(); theq.setQuery(query); theq.setStart(0); theq.setRows(10000); QueryResponse response = new QueryResponse(); response = solr.query(theq); SolrDocumentList list = response.getResults(); int docnum = 1; for (SolrDocument doc : list) { Publication currlist = new Publication(); List<String> fullnames = new ArrayList<String>(); String currepubsum1 = "", currepubsum2 = ""; if (doc.getFieldValue("abstract") != null) { currlist.setAbstract(doc.getFieldValue("abstract").toString()); } if (doc.getFieldValue("ptitle") != null) { currlist.setTitle(doc.getFieldValue("ptitle").toString()); } if (doc.getFieldValue("author_fullname_list") != null) { currlist.setFirst5authors(doc.getFieldValue("author_fullname_list").toString()); } if (doc.getFieldValue("pmid") != null) { currlist.setPmid(Integer.valueOf(doc.getFieldValue("pmid").toString())); } if (doc.getFieldValue("completion") != null) { currlist.setCompletion(Boolean.valueOf(doc.getFieldValue("completion").toString())); } if (doc.getFieldValue("lruid") != null) { currlist.setLruid(doc.getFieldValue("lruid").toString()); } if (doc.getFieldValue("draftpoint") != null) { currlist.setDraftpoint(Integer.valueOf(doc.getFieldValue("draftpoint").toString())); } if (doc.getFieldValue("journalname") != null) { currlist.setJournalname(doc.getFieldValue("journalname").toString()); } if (doc.getFieldValue("journalyear") != null) { currlist.setJournalyear(doc.getFieldValue("journalyear").toString()); } if (doc.getFieldValue("journalday") != null) { currlist.setJournalday(doc.getFieldValue("journalday").toString()); } if (doc.getFieldValue("journalmonth") != null) { currlist.setJournalmonth(doc.getFieldValue("journalmonth").toString()); } if (doc.getFieldValue("journalpage") != null) { currlist.setJournalstartpg(doc.getFieldValue("journalpage").toString()); } if (doc.getFieldValue("journalissue") != null) { currlist.setJournalissue(doc.getFieldValue("journalissue").toString()); } if (doc.getFieldValue("journalvolume") != null) { currlist.setJournalvolume(doc.getFieldValue("journalvolume").toString()); } if (doc.getFieldValue("publicationdate_year") != null) { currlist.setYear(doc.getFieldValue("publicationdate_year").toString()); } if (doc.getFieldValue("doi") != null) { currlist.setDoi(doc.getFieldValue("doi").toString()); } if (doc.getFieldValues("pfileinfo") != null) { Collection<Object> currcoll = doc.getFieldValues("pfileinfo"); for (Object currobj : currcoll) { currlist.getFilesanddata().add(currobj.toString()); } } if (doc.getFieldValue("author_firstname") != null) { currlist.setFauthors((List<String>) doc.getFieldValue("author_firstname")); } if (doc.getFieldValue("author_lastname") != null) { currlist.setLauthors((List<String>) doc.getFieldValue("author_lastname")); } if (doc.getFieldValue("epubmonth") != null) { currlist.setEpubmonth(doc.getFieldValue("epubmonth").toString()); } if (doc.getFieldValue("epubyear") != null) { currlist.setEpubyear(doc.getFieldValue("epubyear").toString()); } if (doc.getFieldValue("epubday") != null) { currlist.setEpubday(doc.getFieldValue("epubday").toString()); } int counter = 0; for (String currstring : currlist.getFauthors()) { currstring += " " + currlist.getLauthors().get(counter); fullnames.add(currstring); counter++; } currlist.setFullnames(fullnames); if (currlist.getJournalvolume().length() > 0) { currepubsum2 += currlist.getJournalvolume(); } if (currlist.getJournalissue().length() > 0) { currepubsum2 += "(" + currlist.getJournalissue() + ")" + ":"; } if (currlist.getJournalstartpg().length() > 0) { currepubsum2 += currlist.getJournalstartpg() + "."; } if (currlist.getEpubday().length() < 1 && currlist.getEpubmonth().length() < 1 && currlist.getEpubyear().length() < 1) { currepubsum1 = "[Epub ahead of print]"; } else if (currlist.getEpubyear().length() > 0) { currepubsum1 = "Epub " + currlist.getEpubyear() + " " + currlist.getEpubmonth() + " " + currlist.getEpubday(); } else { currepubsum1 = ""; } currlist.setEpubsum(currepubsum1); currlist.setEpubsum2(currepubsum2); currlist.setIndex(docnum); if (currlist.getCompletion() == false) { currlist.setComp("Hidden"); } else { currlist.setComp("Visible"); } solrrecords.add(currlist); docnum++; } } catch (Exception ex) { System.out.println(ex); } System.out.println("There are a total of this many records gathered: " + solrrecords.size()); }
From source file:com.datasalt.utils.viewbuilder.SolrAdminCoreUtils.java
License:Apache License
public static NamedList<Object> hotSwapCores(SolrServer adminServer, String coreName, String otherCoreName) throws SolrServerException, IOException { CoreAdminRequest aReq = new CoreAdminRequest(); aReq.setAction(CoreAdminAction.SWAP); aReq.setCoreName(coreName);/*from w w w . j av a 2 s .com*/ aReq.setOtherCoreName(otherCoreName); return adminServer.request(aReq); }
From source file:com.github.fengtan.sophie.beans.SolrUtils.java
License:Open Source License
/** * Get list of cores from the remote Solr server. * /*from w w w . j a v a 2 s.co m*/ * @return Map of cores attributes keyed by core name. * @throws SophieException * If the list of cores cannot be fetched. */ @SuppressWarnings("unchecked") public static Map<String, NamedList<Object>> getCores() throws SophieException { CoreAdminRequest request = new CoreAdminRequest(); request.setAction(CoreAdminAction.STATUS); try { CoreAdminResponse response = request.process(Sophie.client); return response.getCoreStatus().asMap(-1); } catch (SolrServerException | IOException | SolrException e) { throw new SophieException("Unable to fetch list of Solr cores", e); } }
From source file:com.github.fengtan.sophie.toolbars.CoresToolbar.java
License:Open Source License
/** * Populate toolbar with buttons.//from w w w. j av a 2 s . c om * * @param composite * Parent composite. */ private void initToolbar(final Composite composite) { Display display = composite.getDisplay(); ClassLoader loader = getClass().getClassLoader(); // Instantiate toolbar. ToolBar toolBar = new ToolBar(composite, SWT.BORDER); // Instantiate images. imgRefresh = new Image(display, loader.getResourceAsStream("toolbar/refresh.png")); imgAdd = new Image(display, loader.getResourceAsStream("toolbar/add.png")); imgDelete = new Image(display, loader.getResourceAsStream("toolbar/delete.png")); imgRename = new Image(display, loader.getResourceAsStream("toolbar/rename.png")); imgSwap = new Image(display, loader.getResourceAsStream("toolbar/swap.png")); imgReload = new Image(display, loader.getResourceAsStream("toolbar/restore.png")); imgReloadAll = new Image(display, loader.getResourceAsStream("toolbar/restore.png")); // Instantiate buttons. itemRefresh = new ToolItem(toolBar, SWT.PUSH); itemRefresh.setImage(imgRefresh); itemRefresh.setText("Refresh"); itemRefresh.setToolTipText("Refresh list of cores"); itemRefresh.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { try { table.refresh(); } catch (SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to refresh list of cores", e)); } } }); new ToolItem(toolBar, SWT.SEPARATOR); itemAdd = new ToolItem(toolBar, SWT.PUSH); itemAdd.setImage(imgAdd); itemAdd.setText("Add"); itemAdd.setToolTipText("Add new core"); itemAdd.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String[] labels = new String[] { "Name:", "Instance Directory:", "Config file:", "Schema file:", "Data Directory:", "Transaction log directory:" }; String[] defaultValues = new String[] { "collectionX", "/path/to/solr/collectionX", "solrconfig.xml", "schema.xml", "/path/to/solr/collectionX/data", "/path/to/solr/collectionX/tlog" }; MultipleInputDialog dialog = new MultipleInputDialog(composite.getShell(), "Add new core", labels, defaultValues); dialog.open(); if (dialog.getReturnCode() != IDialogConstants.OK_ID) { return; } try { CoreAdminRequest.createCore(dialog.getValue(0), dialog.getValue(1), Sophie.client, dialog.getValue(2), dialog.getValue(3), dialog.getValue(4), dialog.getValue(5)); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to add new core \"" + dialog.getValue(0) + "\"", e)); } } }); itemDelete = new ToolItem(toolBar, SWT.PUSH); itemDelete.setImage(imgDelete); itemDelete.setText("Delete"); itemDelete.setToolTipText("Delete core"); itemDelete.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String coreName = table.getSelectedCore(); MessageBox messageBox = new MessageBox(composite.getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); messageBox.setText("Delete core"); messageBox.setMessage("Do you really want to delete this core (\"" + coreName + "\") ?"); int response = messageBox.open(); if (response == SWT.YES) { try { CoreAdminRequest.unloadCore(coreName, Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to delete core \"" + coreName + "\"", e)); } } } }); itemDelete.setEnabled(false); itemRename = new ToolItem(toolBar, SWT.PUSH); itemRename.setImage(imgRename); itemRename.setText("Rename"); itemRename.setToolTipText("Rename core"); itemRename.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String oldCoreName = table.getSelectedCore(); InputDialog newCoreName = new InputDialog(composite.getShell(), "Rename core", "New name (\"" + oldCoreName + "\"):", oldCoreName, null); newCoreName.open(); if (newCoreName.getReturnCode() != IDialogConstants.OK_ID) { return; } try { CoreAdminRequest.renameCore(oldCoreName, newCoreName.getValue(), Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException( "Unable to rename core \"" + oldCoreName + "\" into \"" + newCoreName + "\"", e)); } } }); itemRename.setEnabled(false); new ToolItem(toolBar, SWT.SEPARATOR); itemSwap = new ToolItem(toolBar, SWT.PUSH); itemSwap.setImage(imgSwap); itemSwap.setText("Swap"); itemSwap.setToolTipText("Swap cores"); itemSwap.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String coreName = table.getSelectedCore(); Map<String, NamedList<Object>> cores; try { cores = SolrUtils.getCores(); } catch (SophieException e) { Sophie.log.error("Unable to suggest list of cores", e); cores = Collections.emptyMap(); } Object[] coreObjects = cores.keySet().toArray(); String[] coreStrings = Arrays.copyOf(coreObjects, coreObjects.length, String[].class); CComboDialog dialog = new CComboDialog(composite.getShell(), "Swap cores", "Swap core \"" + coreName + "\" with:", coreStrings, null); dialog.open(); if (dialog.getReturnCode() != IDialogConstants.OK_ID) { return; } CoreAdminRequest request = new CoreAdminRequest(); request.setCoreName(coreName); request.setOtherCoreName(dialog.getValue()); request.setAction(CoreAdminAction.SWAP); try { request.process(Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException( "Unable to swap cores \"" + coreName + "\" and \"" + dialog.getValue() + "\"", e)); } } }); itemSwap.setEnabled(false); itemReload = new ToolItem(toolBar, SWT.PUSH); itemReload.setImage(imgReload); itemReload.setText("Reload"); itemReload.setToolTipText( "Reload core - this will reload any configuration changes you may have made to solrconfig.xml or schema.xml"); itemReload.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { String coreName = table.getSelectedCore(); try { CoreAdminRequest.reloadCore(coreName, Sophie.client); table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to reload core \"" + coreName + "\"", e)); } } }); itemReload.setEnabled(false); itemReloadAll = new ToolItem(toolBar, SWT.PUSH); itemReloadAll.setImage(imgReloadAll); itemReloadAll.setText("Reload all"); itemReloadAll.setToolTipText("Reload all cores"); itemReloadAll.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { try { for (String coreName : SolrUtils.getCores().keySet()) { CoreAdminRequest.reloadCore(coreName, Sophie.client); } table.refresh(); } catch (SolrServerException | IOException | SolrException | SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to reload all cores", e)); } } }); toolBar.pack(); }
From source file:com.k_joseph.apps.multisearch.solr.AddCustomFieldsToSchema.java
License:Mozilla Public License
/** * Reads the schema file line by line and edits it to add a new field entry * // w w w .java 2 s . c o m * @param schemaFileLocation * @param fieldEntry, the field entry line, use * {@link #generateAWellWrittenFieldEntry(String, String, boolean, boolean, boolean)} * @return new lines of the file in a List */ public static void readSchemaFileLineByLineAndWritNewFieldEntries(String schemaFileLocation, String newSchemaFilePath, String fieldEntry, String copyFieldEntry, SolrServer solrServer) { //reading file line by line in Java using BufferedReader FileInputStream fis = null; BufferedReader reader = null; boolean replacedSchemaWithBackUp = replaceSchemaFileWithItsBackup(schemaFileLocation); if (replacedSchemaWithBackUp) { System.out.println("Successfully replaced the schema.xml file with a previously backed-up copy"); } try { fis = new FileInputStream(schemaFileLocation); reader = new BufferedReader(new InputStreamReader(fis)); System.out.println("Reading " + schemaFileLocation + " file line by line using BufferedReader"); File newSchemaFile = new File(newSchemaFilePath); if (newSchemaFile.exists()) newSchemaFile.delete(); String line = reader.readLine(); while (line != null) { FileWriter fileWritter = new FileWriter(newSchemaFile, true); BufferedWriter bufferWritter = new BufferedWriter(fileWritter); //write to the file from here. if (line.equals("\t\t<!-- Fields from modules and other projects starts here -->")) { bufferWritter.write("\t\t<!-- Fields from modules and other projects starts here -->\n" + fieldEntry + "\n"); bufferWritter.close(); } else if (line.equals("\t<!-- Starting customly added copyfields -->")) { bufferWritter .write("\n\t<!-- Starting customly added copyfields -->\n" + copyFieldEntry + "\n"); bufferWritter.close(); } else { bufferWritter.write(line + "\n"); bufferWritter.close(); } line = reader.readLine(); } } catch (FileNotFoundException ex) { Logger.getLogger(AddCustomFieldsToSchema.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AddCustomFieldsToSchema.class.getName()).log(Level.SEVERE, null, ex); } finally { try { reader.close(); fis.close(); } catch (IOException ex) { Logger.getLogger(AddCustomFieldsToSchema.class.getName()).log(Level.SEVERE, null, ex); } } copyNewSchemaFileToPreviouslyUsed(schemaFileLocation, newSchemaFilePath); CoreAdminRequest adminRequest = new CoreAdminRequest(); reloadSolrServer(solrServer, adminRequest); }
From source file:com.stratio.decision.service.SolrOperationsService.java
License:Apache License
public List<String> getCoreList() throws IOException, SolrServerException { SolrClient solrClient = getSolrclient(null); CoreAdminRequest coreAdminRequest = new CoreAdminRequest(); coreAdminRequest.setAction(CoreAdminParams.CoreAdminAction.STATUS); CoreAdminResponse cores = coreAdminRequest.process(solrClient); List<String> coreList = new ArrayList<String>(); for (int i = 0; i < cores.getCoreStatus().size(); i++) { coreList.add(cores.getCoreStatus().getName(i)); }/*from w w w. j a va 2s .c om*/ return coreList; }
From source file:edu.jhu.cvrg.ceptools.main.PubMedSearch.java
License:Apache License
public void SearchSolr(int mypmid) { int currpmid = mypmid; try {/*from w ww . ja v a2 s .co m*/ CoreAdminRequest adminRequest = new CoreAdminRequest(); adminRequest.setAction(CoreAdminAction.RELOAD); SolrServer solr = new HttpSolrServer("http://localhost:8983/solr"); String query; query = "pmid:" + currpmid; SolrQuery theq = new SolrQuery(); theq.setQuery(query); QueryResponse response = new QueryResponse(); response = solr.query(theq, org.apache.solr.client.solrj.SolrRequest.METHOD.POST); SolrDocumentList list = response.getResults(); for (SolrDocument doc : list) { Publication currlist = new Publication(); currlist.setTitle(doc.getFieldValue("ptitle").toString()); currlist.setAbstract(doc.getFieldValue("abstract").toString()); currlist.setPmid(Integer.valueOf(doc.getFieldValue("pmid").toString())); results.add(currlist); } } catch (Exception ex) { logger.info(ex); StringWriter stack = new StringWriter(); ex.printStackTrace(new PrintWriter(stack)); } }
From source file:edu.jhu.cvrg.ceptools.main.PubMedSearch.java
License:Apache License
public void SearchSolrList(List<Integer> mypmids) { String querylist = "pmid:("; List<Publication> results2 = new ArrayList<Publication>(); for (Integer currint : mypmids) { querylist += currint + " OR "; }/*from w w w.jav a 2s.c om*/ if (querylist.length() > 5) { querylist = querylist.substring(0, querylist.length() - 4); querylist += ")"; } try { CoreAdminRequest adminRequest = new CoreAdminRequest(); adminRequest.setAction(CoreAdminAction.RELOAD); SolrServer solr = new HttpSolrServer("http://localhost:8983/solr"); SolrQuery theq = new SolrQuery(); theq.setQuery(querylist); QueryResponse response = new QueryResponse(); response = solr.query(theq, org.apache.solr.client.solrj.SolrRequest.METHOD.POST); SolrDocumentList list = response.getResults(); for (SolrDocument doc : list) { Publication currlist = new Publication(); solrindex = 0; currlist.setTitle(doc.getFieldValue("ptitle").toString()); currlist.setAbstract(doc.getFieldValue("abstract").toString()); currlist.setPmid(Integer.valueOf(doc.getFieldValue("pmid").toString())); currlist.setCompleted(Boolean.valueOf(doc.getFieldValue("completion").toString())); if (doc.getFieldValue("lruid") != null) { currlist.setUserid(Integer.valueOf(doc.getFieldValue("lruid").toString())); } else { currlist.setUserid(0); } if (doc.getFieldValues("pfileinfo") != null) { Collection<Object> currcoll = doc.getFieldValues("pfileinfo"); for (Object currobj : currcoll) { currlist = convertStore(String.valueOf(currobj), currlist); } } results2.add(currlist); } int currcounter = 0; for (Publication solrmatch : results2) { currcounter = 0; for (Publication publistrecord : publications) { if (solrmatch.getPmid() == publistrecord.getPmid()) { publications.get(currcounter).setExists(true); publications.get(currcounter).setCompleted(solrmatch.getCompleted()); publications.get(currcounter).setFstorefiles(solrmatch.getFstorefiles()); publications.get(currcounter).setUserid(solrmatch.getUserid()); } currcounter++; } } } catch (Exception ex) { logger.error("Error : ", ex); } }
From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java
License:Apache License
public Set<String> getSolrCoreList() { // Request core list SolrClientAPIExec.logger.debug("Getting cores from solr.."); CoreAdminRequest request = new CoreAdminRequest(); request.setAction(CoreAdminAction.STATUS); Set<String> coreList = null; try {/*from w ww . j av a2 s .c om*/ CoreAdminResponse cores = request.process(solrClient); coreList = new HashSet<String>(cores.getCoreStatus().size()); for (int i = 0; i < cores.getCoreStatus().size(); i++) { String coreName = cores.getCoreStatus().getName(i); coreList.add(coreName); } } catch (SolrServerException | IOException e) { SolrClientAPIExec.logger.info("Error getting core info from solr server..."); } return coreList; }
From source file:org.apache.ranger.services.solr.client.ServiceSolrClient.java
License:Apache License
public List<String> getCoresList(List<String> ignoreCollectionList) throws Exception { CoreAdminRequest request = new CoreAdminRequest(); request.setAction(CoreAdminAction.STATUS); CoreAdminResponse cores = request.process(solrClient); // List of the cores List<String> coreList = new ArrayList<String>(); for (int i = 0; i < cores.getCoreStatus().size(); i++) { if (ignoreCollectionList == null || !ignoreCollectionList.contains(cores.getCoreStatus().getName(i))) { coreList.add(cores.getCoreStatus().getName(i)); }/*from w w w . j ava 2 s . c o m*/ } return coreList; }