@RequestMapping("/drug")
  public String search(
      @RequestParam(value = "name", defaultValue = "") String name,
      @RequestParam(value = "limit", defaultValue = "10") int limit,
      @RequestParam(value = "skip", defaultValue = "0") int skip)
      throws IOException {
    name = fixTerm.makeFdaSafe(name);
    if (name.length() == 0) {
      return "[]";
    }

    List<DrugSearchResult> rv = new LinkedList<DrugSearchResult>();

    Set<String> uniis = this.getUniisByName(name);
    Map<String, Set<String>> brandNames = this.getBrandNamesByNameAndUniis(name, uniis);

    // create full list of drug search results
    for (String unii : uniis) {
      for (String brandName : brandNames.get(unii)) {
        DrugSearchResult res = new DrugSearchResult();
        res.setUnii(unii);
        res.setBrandName(brandName);
        rv.add(res);
      }
    }

    // sort the list of drug search results by custom comparator
    Collections.sort(rv, new DrugSearchComparator(name));

    // implement skip/limit
    if (rv.size() > 0) {
      rv = rv.subList(skip, Math.min(rv.size(), skip + limit));
    }

    // fill in details for all the results we're returning
    for (DrugSearchResult res : rv) {
      res.setRxcui(this.getRxcuiByUnii(res.getUnii()));
      res.setGenericName(this.getGenericNameByRxcui(res.getRxcui()));
      if (res.getActiveIngredients().isEmpty() && res.getGenericName() != null) {
        res.setActiveIngredients(
            new TreeSet<String>(Arrays.asList(res.getGenericName().split(", "))));
      }
    }

    ObjectMapper mapper = new ObjectMapper();
    return mapper.writeValueAsString(rv);
  }
 private List firstTenMarks(Set<Mark> input) {
   List<Mark> marksList = new ArrayList<>(input);
   Collections.sort(marksList, Collections.reverseOrder());
   return marksList.size() <= 10 ? marksList : marksList.subList(0, 10);
 }