final SolrDocument lastSolrDocument = documentList.get(response.getResults().size()-1); final String latestDateValue = df.format(lastSolrDocument.get(dateField)); final String newCursorMark = response.getNextCursorMark();
@Override public Document getLatest(String guid, String sensorType) throws IOException { if (MetaAlertConstants.METAALERT_TYPE.equals(sensorType)) { // Unfortunately, we can't just defer to the indexDao for this. Child alerts in Solr end up // having to be dug out. String guidClause = Constants.GUID + ":" + guid; SolrQuery query = new SolrQuery(); query.setQuery(guidClause) .setFields("*", "[child parentFilter=" + guidClause + " limit=999]"); try { QueryResponse response = solrDao.getSolrClient(solrDao.getZkHosts()) .query(METAALERTS_COLLECTION, query); // GUID is unique, so it's definitely the first result if (response.getResults().size() == 1) { SolrDocument result = response.getResults().get(0); return SolrUtilities.toDocument(result); } else { return null; } } catch (SolrServerException e) { throw new IOException("Unable to retrieve metaalert", e); } } else { return solrDao.getLatest(guid, sensorType); } }
private ServerDetail fetchServerDetails(String hostname, String coreName, SolrServer realTimeThoth) throws SolrServerException { System.out.println("Fetching server details for hostname("+hostname+") coreName("+coreName+")"); QueryResponse qr = realTimeThoth.query(new SolrQuery("hostname_s:\"" + hostname + "\"" +" AND " + "coreName_s:\"" +coreName + "\" AND NOT exception_b:true AND NOT slowQuery_b:true").setRows(1)); SolrDocumentList solrDocumentList = qr.getResults(); ServerDetail sd = null; if (qr.getResults().getNumFound() > 0) { String pool = (String)solrDocumentList.get(0).getFieldValue(POOL); String port = solrDocumentList.get(0).getFieldValue(PORT).toString(); sd = new ServerDetail(hostname, pool, port, coreName); } return sd; }
public SearchResultList getSearchResultList(SolrDocumentList list) { SearchResultList results = new SearchResultList(); results.setNumFound(list.getNumFound()); for (int i = 0; i < list.size(); ++i) { results.add(getSearchResult(list.get(i))); } return results; }
@Override public SearchResultDocument get(int i) { return convertToSearchResultDocument(solrDocs.get(i)); }
String qry="*:*"; SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(Integer.MAX_VALUE); //Add me to avoid IndexOutOfBoundExc CommonsHttpSolrServer server = new CommonsHttpSolrServer("http://localhost:8983/solr"); QueryResponse rsp=server.query(query); SolrDocumentList docs=rsp.getResults(); for(int i=0;i<docs.getNumFound();i++){ System.out.println(docs.get(i)); }
public static void doQuery(SolrClient ss, String id) throws SolrServerException, IOException { SolrParams p = new SolrQuery("id:\"" + id + "\""); QueryResponse r = ss.query(p); System.out.println("GOT collection " + r.getResults().get(0).getFieldValue("collection")); System.out.println("GOT collections " + r.getResults().get(0).getFieldValue("collections")); System.out.println("STILL GOT crawl_date " + r.getResults().get(0).getFieldValue("crawl_date")); }
public static SolrDocument querySingle(SolrServer server, SolrQuery solrParams) throws SolrSearchEmptyException { try { solrParams.addSortField("item.id", ORDER.asc); QueryResponse response = server.query(solrParams); if (response.getResults().getNumFound() > 0) { return response.getResults().get(0); } else { throw new SolrSearchEmptyException(); } } catch (SolrServerException ex) { throw new SolrSearchEmptyException(ex.getMessage(), ex); } } }
public static void doQuery(SolrClient ss, String id) throws SolrServerException, IOException { SolrParams p = new SolrQuery("id:\"" + id + "\""); QueryResponse r = ss.query(p); System.out.println("GOT collection " + r.getResults().get(0).getFieldValue("collection")); System.out.println("GOT collections " + r.getResults().get(0).getFieldValue("collections")); System.out.println("STILL GOT crawl_date " + r.getResults().get(0).getFieldValue("crawl_date")); }
@Override public String getColumnName(int columnIndex) { if(response == null || response.getResults().size() == 0) { return ""; } List<String> list = new LinkedList<String>(response.getResults().get(0).getFieldNames()); return list.get(columnIndex); }
public HakukohteetVastaus convertSolrToHakukohteetVastaus(SolrDocumentList solrHakukohdeList, Map<String, OrganisaatioPerustieto> orgResponse, String defaultTarjoaja) { HakukohteetVastaus vastaus = new HakukohteetVastaus(); for (int i = 0; i < solrHakukohdeList.size(); ++i) { SolrDocument hakukohdeDoc = solrHakukohdeList.get(i); HakukohdePerustieto hakukohde = convertHakukohde(hakukohdeDoc, orgResponse, defaultTarjoaja); if (hakukohde != null) { vastaus.getHakukohteet().add(hakukohde); } } return vastaus; }
@Override public Object getValueAt(int rowIndex, int columnIndex) { String columnName = getColumnName(columnIndex); if(response.getHighlighting() != null && response.getHighlighting().get(columnName) != null) { System.out.println(response.getHighlighting().get(columnName)); } return response.getResults().get(rowIndex).getFieldValue(columnName); }
@Override public int getColumnCount() { if(response == null || response.getResults().size() == 0) { return 0; } return response.getResults().get(0).getFieldNames().size(); }
public KoulutuksetVastaus convertSolrToKoulutuksetVastaus(SolrDocumentList solrKomotoList, Map<String, OrganisaatioPerustieto> orgs, String defaultTarjoaja) { KoulutuksetVastaus vastaus = new KoulutuksetVastaus(); for (int i = 0; i < solrKomotoList.size(); ++i) { SolrDocument curDoc = solrKomotoList.get(i); KoulutusPerustieto koulutus = convertKoulutus(curDoc, orgs, defaultTarjoaja); if (koulutus != null) { vastaus.getKoulutukset().add(koulutus); } } return vastaus; }
/** * @param raw * @return The estimated country_code */ public String countryCode(String raw){ try { QueryResponse qres = this.geoindex.query(constructQuery(raw)); SolrDocumentList res = qres.getResults(); return (String) res.get(0).get("country_code"); } catch (SolrServerException e) { } return null; }
public String[] search(final SolrQuery query, final String retrievedField) throws SolrServerException, IOException { final QueryResponse response = this.getServer().query(query); final SolrDocumentList docList = response.getResults(); final int size = docList.size(); final String docIDs[] = new String[size]; SolrDocument doc = null; for (int i = 0; i < size; i++) { doc = docList.get(i); docIDs[i] = (String) doc.getFieldValue(retrievedField); } return docIDs; }
public String[] search(final SolrQuery query, final String retrievedField) throws SolrServerException, IOException { final QueryResponse response = this.getServer().query(query); final SolrDocumentList docList = response.getResults(); final int size = docList.size(); final String docIDs[] = new String[size]; SolrDocument doc = null; for (int i = 0; i < size; i++) { doc = docList.get(i); docIDs[i] = (String) doc.getFieldValue(retrievedField); } return docIDs; }