Example #1
0
 /**
  * 模糊匹配
  *
  * @param keys
  * @return
  */
 private List<LocationIndex> fuzzyQuery(String key) {
   String[] keys = key.trim().split(" ");
   for (int i = 0; i < keys.length; i++) {
     keys[i] = "type_i:" + LocationIndex.TYPE_LEAFLET + " AND description_ss:" + keys[i] + "~";
   }
   return solrService.query(LocationIndex.class, StringUtils.join(keys, " OR "));
 }
Example #2
0
 /**
  * delete a location
  *
  * @param request
  * @return
  */
 @RequestMapping(value = "location/delete", method = RequestMethod.POST)
 public ResponseEntity<JSONObject> deleteLocation(HttpServletRequest request) {
   String id = getString(request, "id");
   JSONObject result = new JSONObject();
   try {
     solrService.delete(id);
     result.put("success", true);
   } catch (SolrServerException | IOException e) {
     logger.error("Add location fail", e);
     result.put("error", e.getLocalizedMessage());
   }
   return new ResponseEntity<JSONObject>(result, HttpStatus.OK);
 }
Example #3
0
 /**
  * @param request
  * @return
  */
 @RequestMapping(value = "locateTile", method = RequestMethod.GET)
 public ResponseEntity<JSONObject> locateTile(HttpServletRequest request) {
   JSONObject result = new JSONObject();
   Float x = getFloat(request, "x");
   Float y = getFloat(request, "y");
   Integer size = getInteger(request, "size"); // 这个不会出现flaot, 应该是2的N次幂
   if (x == null || y == null || size == null) {
     result.put("error", "参数有误,坐标或大小无法取得。");
   } else {
     String query = "type_i:" + LocationIndex.TYPE_LEAFLET;
     query += " AND coordX_f:[" + (x - size / 2) + " TO " + (x + size / 2) + "]";
     query += " AND coordY_f:[" + (y - size / 2) + " TO " + (y + size / 2) + "]";
     List<LocationIndex> list = solrService.query(LocationIndex.class, query);
     logger.info("Query area : " + query + " , hits : " + list.size());
     result.put("result", parseJson(list));
   }
   return new ResponseEntity<JSONObject>(result, HttpStatus.OK);
 }
Example #4
0
  /**
   * edit a location
   *
   * @param request
   * @return
   */
  @RequestMapping(value = "location/edit", method = RequestMethod.POST)
  public ResponseEntity<JSONObject> editLocation(HttpServletRequest request) {
    JSONObject result = new JSONObject();
    String valid = checkParams(request);
    if (valid != null) {
      result.put("error", valid);
      return new ResponseEntity<JSONObject>(result, HttpStatus.OK);
    }

    LocationIndex index = getLocationIndex(request);
    index.setId(getString(request, "id"));
    try {
      solrService.update(index);
      result.put("success", true);
    } catch (SolrServerException | IOException e) {
      logger.error("Add location fail", e);
      result.put("error", e.getLocalizedMessage());
    }
    return new ResponseEntity<JSONObject>(result, HttpStatus.OK);
  }