Esempio n. 1
0
  /**
   * Returns an array where the first value is the search string and the second is a display string.
   *
   * @param lsid
   * @return
   */
  public String[] getTaxonSearch(String lsid) {

    String[] result = new String[0];
    // use the name matching index
    try {
      if (nameIndex == null) {
        nameIndex = new ALANameSearcher(nameIndexLocation);
      }
      NameSearchResult nsr = nameIndex.searchForRecordByLsid(lsid);
      if (nsr != null) {
        String rank = nsr.getRank() != null ? nsr.getRank().toString() : "Unknown Rank";
        String scientificName =
            nsr.getRankClassification() != null
                ? nsr.getRankClassification().getScientificName()
                : null;
        StringBuffer dispSB = new StringBuffer(rank + ": " + scientificName);
        StringBuilder sb = new StringBuilder("lft:[");
        String lft = nsr.getLeft() != null ? nsr.getLeft() : "0";
        String rgt = nsr.getRight() != null ? nsr.getRight() : "0";
        sb.append(lft).append(" TO ").append(rgt).append("]");
        return new String[] {sb.toString(), dispSB.toString()};
      } else {
        return new String[] {
          "taxon_concept_lsid:" + ClientUtils.escapeQueryChars(lsid), "taxon_concept_lsid:" + lsid
        };
      }
    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }

    return result;
  }
Esempio n. 2
0
  /**
   * Extracts the a rank and name from a query.
   *
   * <p>E.g. genus:Macropus will return an a array of <code>
   * new String[]{"genus", "Macropus"};
   * </code>
   *
   * @param query
   */
  public String convertRankAndName(String query) {

    Pattern rankAndName = Pattern.compile("([a-z]{1,})\\:([A-Za-z \\(\\)\\.]{1,})");
    int position = 0;
    Matcher m = rankAndName.matcher(query);
    if (m.find(position) && m.groupCount() == 2) {
      String rank = m.group(1);
      String scientificName = m.group(2);
      RankType rankType = RankType.getForName(rank.toLowerCase());
      if (rankType != null) {
        try {
          NameSearchResult r = Config.nameIndex().searchForRecord(scientificName, rankType);
          if (r != null) {
            return "lft:[" + r.getLeft() + " TO " + r.getRight() + "]";
          }
        } catch (Exception e) {
          // fail silently if the parse failed
        }
      }
    }
    return query;
  }