Esempio n. 1
1
  /**
   * Search datasets containg param text in the metadata
   *
   * @param query The query object
   * @param limit maximum results to return
   * @param offset search begins from offset
   * @throws JackanException on error
   */
  public synchronized SearchResults<CkanDataset> searchDatasets(
      CkanQuery query, int limit, int offset) {

    StringBuilder params = new StringBuilder();

    params.append("rows=").append(limit).append("&start=").append(offset);

    if (query.getText().length() > 0) {
      params.append("&q=");
      params.append(urlEncode(query.getText()));
    }

    StringBuilder fq = new StringBuilder();
    String fqPrefix = "";

    fqPrefix = appendNamesList(fqPrefix, "groups", query.getGroupNames(), fq);
    fqPrefix = appendNamesList(fqPrefix, "organization", query.getOrganizationNames(), fq);
    fqPrefix = appendNamesList(fqPrefix, "tags", query.getTagNames(), fq);
    fqPrefix = appendNamesList(fqPrefix, "license_id", query.getLicenseIds(), fq);

    if (fq.length() > 0) {
      params.append("&fq=").append(urlEncode(fq.insert(0, "(").append(")").toString()));
    }

    DatasetSearchResponse dsr;
    dsr = getHttp(DatasetSearchResponse.class, "/api/3/action/package_search?" + params.toString());

    if (dsr.success) {
      for (CkanDataset ds : dsr.result.getResults()) {
        for (CkanResource cr : ds.getResources()) {
          cr.setPackageId(ds.getId());
        }
      }
    }

    return dsr.result;
  }
Esempio n. 2
0
 /**
  * Search datasets containing provided text in the metadata
  *
  * @param text The query string
  * @param limit maximum results to return
  * @param offset search begins from offset. Starts from 0, so that offset 0 limit 1 returns
  *     exactly 1 result, if there is a matching dataset)
  * @throws JackanException on error
  */
 public synchronized SearchResults<CkanDataset> searchDatasets(
     String text, int limit, int offset) {
   return searchDatasets(CkanQuery.filter().byText(text), limit, offset);
 }