List of usage examples for org.apache.solr.common SolrDocument getFieldValueMap
public Map<String, Object> getFieldValueMap()
From source file:au.org.ala.biocache.web.WMSController.java
License:Open Source License
@RequestMapping(value = { "/ogc/getFeatureInfo" }, method = RequestMethod.GET)
public String getFeatureInfo(
@RequestParam(value = "CQL_FILTER", required = false, defaultValue = "") String cql_filter,
@RequestParam(value = "ENV", required = false, defaultValue = "") String env,
@RequestParam(value = "BBOX", required = true, defaultValue = "0,-90,180,0") String bboxString,
@RequestParam(value = "WIDTH", required = true, defaultValue = "256") Integer width,
@RequestParam(value = "HEIGHT", required = true, defaultValue = "256") Integer height,
@RequestParam(value = "STYLES", required = false, defaultValue = "") String styles,
@RequestParam(value = "SRS", required = false, defaultValue = "") String srs,
@RequestParam(value = "QUERY_LAYERS", required = false, defaultValue = "") String queryLayers,
@RequestParam(value = "X", required = true, defaultValue = "0") Double x,
@RequestParam(value = "Y", required = true, defaultValue = "0") Double y, HttpServletRequest request,
HttpServletResponse response, Model model) throws Exception {
logger.debug("WMS - GetFeatureInfo requested for: " + queryLayers);
if ("EPSG:4326".equals(srs))
bboxString = convertBBox4326To900913(bboxString); // to work around a UDIG bug
WmsEnv vars = new WmsEnv(env, styles);
double[] mbbox = new double[4];
double[] bbox = new double[4];
double[] pbbox = new double[4];
double[] tilebbox = new double[4];
int size = vars.size + (vars.highlight != null ? HIGHLIGHT_RADIUS * 2 + (int) (vars.size * 0.2) : 0) + 5; //bounding box buffer
//what is the size of the dot in degrees
double resolution = getBBoxes(bboxString, width, height, size, vars.uncertainty, mbbox, bbox, pbbox,
tilebbox);//from w w w. j a v a 2s. c o m
//resolution should be a value < 1
PointType pointType = getPointTypeForDegreesPerPixel(resolution);
double longitude = bbox[0] + (((bbox[2] - bbox[0]) / width) * x);
double latitude = bbox[3] - (((bbox[3] - bbox[1]) / height) * y);
//round to the correct point size
double roundedLongitude = pointType.roundToPointType(longitude);
double roundedLatitude = pointType.roundToPointType(latitude);
//get the pixel size of the circles
double minLng = pointType.roundDownToPointType(roundedLongitude - (pointType.getValue() * 2 * (size + 3)));
double maxLng = pointType.roundUpToPointType(roundedLongitude + (pointType.getValue() * 2 * (size + 3)));
double minLat = pointType.roundDownToPointType(roundedLatitude - (pointType.getValue() * 2 * (size + 3)));
double maxLat = pointType.roundUpToPointType(roundedLatitude + (pointType.getValue() * 2 * (size + 3)));
//do the SOLR query
SpatialSearchRequestParams requestParams = new SpatialSearchRequestParams();
String q = convertLayersParamToQ(queryLayers);
requestParams.setQ(convertLayersParamToQ(queryLayers)); //need to derive this from the layer name
logger.debug("WMS GetFeatureInfo for " + queryLayers + ", longitude:[" + minLng + " TO " + maxLng
+ "], latitude:[" + minLat + " TO " + maxLat + "]");
String[] fqs = new String[] { "longitude:[" + minLng + " TO " + maxLng + "]",
"latitude:[" + minLat + " TO " + maxLat + "]" };
requestParams.setFq(fqs);
//requestParams.setFq(new String[]{"point-"+pointType.getValue()+":"+roundedLatitude+","+roundedLongitude});
requestParams.setFacet(false);
//TODO: paging
SolrDocumentList sdl = searchDAO.findByFulltext(requestParams);
//send back the results.
String body = "";
if (sdl != null && sdl.size() > 0) {
SolrDocument doc = sdl.get(0);
model.addAttribute("record", doc.getFieldValueMap());
model.addAttribute("totalRecords", sdl.getNumFound());
}
model.addAttribute("uriUrl",
"http://biocache.ala.org.au/occurrences/search?q=" + URLEncoder.encode(q, "UTF-8") + "&fq="
+ URLEncoder.encode(fqs[0], "UTF-8") + "&fq=" + URLEncoder.encode(fqs[1], "UTF-8"));
model.addAttribute("pointType", pointType.name());
model.addAttribute("minLng", minLng);
model.addAttribute("maxLng", maxLng);
model.addAttribute("minLat", minLat);
model.addAttribute("maxLat", maxLat);
model.addAttribute("latitudeClicked", latitude);
model.addAttribute("longitudeClicked", longitude);
return "metadata/getFeatureInfo";
}
From source file:de.dlr.knowledgefinder.webapp.webservice.service.impl.KnowledgeFinderServiceImpl.java
License:Apache License
private void replaceHightlighting(SolrDocumentList result, Map<String, Map<String, List<String>>> hl) { if (hl != null && hl.size() > 0) { for (SolrDocument res : result) { Map<String, Object> fields = res.getFieldValueMap(); String id = (String) fields.get("id"); Map<String, List<String>> hlValueMap = hl.get(id); if (hlValueMap != null) { for (String hlValueMapKey : hlValueMap.keySet()) { List<String> hlValue = hlValueMap.get(hlValueMapKey); if (hlValue.size() > 0) { res.setField(hlValueMapKey, hlValue); }//from w ww .j a v a 2s. com } } } } }
From source file:fr.aliacom.obm.common.contact.ContactDao.java
License:Open Source License
private List<Contact> searchContact(AccessToken at, List<AddressBook> addrBooks, Connection con, String querys, int limit) throws MalformedURLException, SQLException { List<Contact> ret = new LinkedList<Contact>(); Set<Integer> evtIds = new HashSet<Integer>(); PreparedStatement ps = null;/*from w w w . ja va2 s. c o m*/ ResultSet rs = null; try { if (addrBooks.size() > 0) { SolrHelper solrHelper = solrHelperFactory.createClient(at); CommonsHttpSolrServer solrServer = solrHelper.getSolrContact(); StringBuilder sb = new StringBuilder(); sb.append("-is:archive "); sb.append("+addressbookId:("); int idx = 0; for (AddressBook book : addrBooks) { if (idx > 0) { sb.append(" OR "); } sb.append(book.getUid()); idx++; } sb.append(")"); if (querys != null && !"".equals(querys)) { sb.append(" +(displayname:("); sb.append(querys.toLowerCase()); sb.append("*) OR firstname:("); sb.append(querys.toLowerCase()); sb.append("*) OR lastname:("); sb.append(querys.toLowerCase()); sb.append("*) OR email:("); sb.append(querys.toLowerCase()); sb.append("*))"); } SolrQuery params = new SolrQuery(); params.setQuery(sb.toString()); params.setIncludeScore(true); params.setRows(limit); try { QueryResponse resp = solrServer.query(params); SolrDocumentList results = resp.getResults(); if (logger.isDebugEnabled()) { logger.debug("SOLR query time for " + results.size() + " results: " + resp.getElapsedTime() + "ms."); } for (int i = 0; i < limit && i < results.size(); i++) { SolrDocument doc = results.get(i); Map<String, Object> payload = doc.getFieldValueMap(); evtIds.add((Integer) payload.get("id")); } } catch (SolrServerException e) { logger.error("Error querying server for '" + sb.toString() + " url: " + ClientUtils.toQueryString(params, false), e); } } IntegerSQLCollectionHelper eventIds = new IntegerSQLCollectionHelper(evtIds); String q = "SELECT " + CONTACT_SELECT_FIELDS + ", now() as last_sync FROM Contact, ContactEntity WHERE " + "contactentity_contact_id=contact_id AND contact_archive != 1 AND contact_id IN (" + eventIds.asPlaceHolders() + ")"; ps = con.prepareStatement(q); eventIds.insertValues(ps, 1); rs = ps.executeQuery(); Map<Integer, Contact> entityContact = new HashMap<Integer, Contact>(); int i = 0; while (rs.next() && i < limit) { int entity = rs.getInt("contactentity_entity_id"); if (!entityContact.containsKey(entity)) { Contact ct = contactFromCursor(rs); entityContact.put(ct.getEntityId(), ct); ret.add(ct); i++; } } rs.close(); rs = null; if (!entityContact.isEmpty()) { loadPhones(con, entityContact); loadIMIdentifiers(con, entityContact); loadWebsites(con, entityContact); loadAddresses(at, con, entityContact); loadEmails(con, entityContact); loadBirthday(con, entityContact); loadAnniversary(con, entityContact); } } finally { obmHelper.cleanup(null, ps, rs); } return ret; }
From source file:fr.aliacom.obm.common.contact.ContactDaoJdbcImpl.java
License:Open Source License
private List<Contact> searchContact(AccessToken at, Collection<AddressBook> addrBooks, Connection con, String query, int limit, Integer offset) throws MalformedURLException, SQLException, LocatorClientException { Set<Integer> contactIds = new HashSet<Integer>(); if (addrBooks.size() > 0) { SolrHelper solrHelper = solrHelperFactory.createClient(at); CommonsHttpSolrServer solrServer = solrHelper.getSolrContact(); StringBuilder sb = new StringBuilder(); sb.append("-is:archive "); sb.append("+addressbookId:("); int idx = 0; for (AddressBook book : addrBooks) { if (idx > 0) { sb.append(" OR "); }// www. j ava2s . c om sb.append(book.getUid()); idx++; } sb.append(")"); if (query != null && !"".equals(query)) { sb.append(" +(displayname:("); sb.append(query.toLowerCase()); sb.append("*) OR firstname:("); sb.append(query.toLowerCase()); sb.append("*) OR lastname:("); sb.append(query.toLowerCase()); sb.append("*) OR email:("); sb.append(query.toLowerCase()); sb.append("*))"); } SolrQuery params = new SolrQuery(); params.setQuery(sb.toString()); params.setIncludeScore(true); params.setRows(limit); params.setStart(offset); try { QueryResponse resp = solrServer.query(params); SolrDocumentList results = resp.getResults(); if (logger.isDebugEnabled()) { logger.debug( "SOLR query time for " + results.size() + " results: " + resp.getElapsedTime() + "ms."); } for (int i = 0; i < limit && i < results.size(); i++) { SolrDocument doc = results.get(i); Map<String, Object> payload = doc.getFieldValueMap(); contactIds.add((Integer) payload.get("id")); } } catch (SolrServerException e) { logger.error("Error querying server for '" + sb.toString() + " url: " + ClientUtils.toQueryString(params, false), e); } } ContactResults contactResults = loadContactsFromDB(contactIds, con, limit); if (!contactResults.contactMap.isEmpty()) { loadPhones(con, contactResults.contactMap); loadIMIdentifiers(con, contactResults.contactMap); loadWebsites(con, contactResults.contactMap); loadAddresses(at, con, contactResults.contactMap); loadEmails(con, contactResults.contactMap); loadBirthday(con, contactResults.contactMap); loadAnniversary(con, contactResults.contactMap); } return contactResults.contactList; }
From source file:fr.aliasource.index.solr.SolrClient.java
License:GNU General Public License
@Override public List<Hit> doQuery(String query) { Matcher m = p.matcher(query); String begin = "1969-01-01T00:00:00Z"; String end = "2040-01-01T00:00:00Z"; while (m.find()) { String s = query.substring(m.start(), m.end()); if (s.startsWith("before:")) { end = s.split(":")[1] + "T23:59:59Z"; }/*from ww w . j a va2 s.c o m*/ if (s.startsWith("after:")) { begin = s.split(":")[1] + "T00:00:00Z"; } } String date = "date:[" + begin + " TO " + end + "]"; StringBuilder sb = new StringBuilder(); sb.append(date).append(' ').append(query.replaceAll(regexpDate, "")); String parsedQuery = sb.toString(); if (logger.isDebugEnabled()) { logger.debug("doQuery(" + parsedQuery + ")"); } List<Hit> ret = null; SolrParams params = createParams(parsedQuery); try { QueryResponse resp = solrServer.query(params); SolrDocumentList results = resp.getResults(); if (logger.isDebugEnabled()) { logger.debug( "SOLR query time for " + results.size() + " results: " + resp.getElapsedTime() + "ms."); } ret = new ArrayList<Hit>(results.size()); for (SolrDocument doc : results) { Map<String, Object> payload = doc.getFieldValueMap(); Hit hit = new Hit(payload, getType()); ret.add(hit); } } catch (SolrServerException e) { logger.error("Error querying server for '" + parsedQuery + "' (type: " + getType() + "), url: " + ClientUtils.toQueryString(params, false), e); ret = new LinkedList<Hit>(); } return ret; }
From source file:net.hydromatic.optiq.impl.solr.SolrEnumerator.java
License:Apache License
private Object[] convertRow(SolrDocument strings) { final Object[] objects = new Object[fields.length]; Collection<String> f1 = strings.getFieldNames(); Map<String, Object> f2 = strings.getFieldValueMap(); for (String entry : f1) { final Object string = f2.get(entry); objects[findPosition(entry)] = string; }//from www .j a va 2 s .co m // THIS IS A FUDGE for MONDRIAN-1610 and needs removing ASAP. for (int i = 0; i < objects.length; i++) { if (objects[i] == null) { SolrFieldType o = fieldTypes[i]; String n = ""; if (o != null) { n = o.name(); } if (n == "") { objects[i] = "N/A"; } else if (n == "STRING") { objects[i] = "N/A"; } else if (n == "FLOAT") { /* float b= 3.6f; objects[i] = b;*/ } else if (n == "DATE") { //objects[i] = new Date(0); } else if (n == "INTEGER") { // objects[i] = 0; } else if (n == "BOOLEAN") { //objects[i] = false; } } } return objects; }
From source file:net.yacy.cora.federate.solr.responsewriter.EnhancedXMLResponseWriter.java
License:Open Source License
public static final void writeDoc(final Writer writer, final SolrDocument doc) throws IOException { startTagOpen(writer, "doc", null); final Map<String, Object> fields = doc.getFieldValueMap(); for (String key : fields.keySet()) { if (key == null) continue; Object value = doc.get(key); if (value == null) { } else if (value instanceof Collection<?>) { startTagOpen(writer, "arr", key); writer.write(lb);//from w w w . ja v a 2 s.c om for (Object o : ((Collection<?>) value)) { writeField(writer, null, o); } writer.write("</arr>"); writer.write(lb); } else { writeField(writer, key, value); } } writer.write("</doc>"); writer.write(lb); }
From source file:net.yacy.cora.federate.solr.responsewriter.FlatJSONResponseWriter.java
License:Open Source License
public static final void writeDoc(final Writer writer, final SolrDocument doc) throws IOException { JSONObject json = new JSONObject(true); final Map<String, Object> fields = doc.getFieldValueMap(); for (String key : fields.keySet()) { if (key == null) continue; Object value = doc.get(key); if (value == null) { } else if (value instanceof Collection<?>) { JSONArray a = new JSONArray(); json.put(key, a);/* w w w . j av a2s . c om*/ for (Object o : ((Collection<?>) value)) { a.add(o); } } else { json.put(key, value); } } writer.write(json.toString()); writer.write(lb); }
From source file:nl.b3p.viewer.search.PDOKSearchClient.java
License:Open Source License
private JSONObject solrDocumentToResult(SolrDocument doc) { JSONObject result = null;//from ww w .j ava 2s .c o m try { Map<String, Object> values = doc.getFieldValueMap(); result = new JSONObject(); for (String key : values.keySet()) { switch (key) { // some fields to skip case "geometrie_rd": case "boundingbox_rd": case "centroide_rd": // because calculated clientside break; default: result.put(key, values.get(key)); } } String geom = (String) doc.getFieldValue("centroide_rd"); if (values.containsKey("geometrie_rd")) { geom = (String) values.get("geometrie_rd"); } else if (values.containsKey("boundingbox_rd")) { geom = (String) values.get("boundingbox_rd"); } Geometry g = wkt.read(geom); if (g instanceof Point) { // if got a point buffer the geom Double d = BUFFERS.get(result.getString("type")); if (d == null) { // unknown type in response, fall back to "weg" d = BUFFERS.get("weg"); } g = g.buffer(d); } if (geom != null) { Envelope env = g.getEnvelopeInternal(); Map bbox = new HashMap(); bbox.put("minx", env.getMinX()); bbox.put("miny", env.getMinY()); bbox.put("maxx", env.getMaxX()); bbox.put("maxy", env.getMaxY()); result.put("location", bbox); } result.put("label", values.get("weergavenaam")); } catch (JSONException | ParseException ex) { log.error(ex); } return result; }
From source file:nl.knaw.huygens.timbuctoo.index.solr.SolrIndex.java
License:Open Source License
private List<Map<String, Object>> getSingleRawResults(SolrQuery solrQuery) throws SearchException { QueryResponse queryResponse;/*from w w w . ja v a2s. c o m*/ try { queryResponse = solrServer.search(solrQuery); } catch (SolrServerException e) { throw new SearchException(e); } List<Map<String, Object>> results = Lists.newArrayList(); for (SolrDocument doc : queryResponse.getResults()) { results.add(doc.getFieldValueMap()); } return results; }