001package org.gbif.api.model.registry.search;
002
003import org.gbif.api.model.common.paging.Pageable;
004import org.gbif.api.model.common.search.FacetedSearchRequest;
005import org.gbif.api.model.registry.Tag;
006import org.gbif.api.vocabulary.Continent;
007import org.gbif.api.vocabulary.Country;
008import org.gbif.api.vocabulary.DatasetSubtype;
009import org.gbif.api.vocabulary.DatasetType;
010
011import java.util.UUID;
012
013/**
014 * A dataset specific search request with convenience methods to add facet filters.
015 */
016public class DatasetSearchRequest extends FacetedSearchRequest<DatasetSearchParameter> {
017  private Integer highlightContext = -1;
018
019  public DatasetSearchRequest() {
020  }
021
022  public DatasetSearchRequest(Pageable page) {
023    super(page);
024  }
025
026  public DatasetSearchRequest(long offset, int limit) {
027    super(offset, limit);
028  }
029
030  /**
031   * @return the number of characters of the context to show for the highlighted match, including the match itself.
032   */
033  public Integer getHighlightContext() {
034    return highlightContext;
035  }
036
037  public void setHighlightContext(Integer highlightContext) {
038    this.highlightContext = highlightContext;
039  }
040
041  /**
042   * Filters dataset by the owning organizations country.
043   */
044  public void addPublishingCountryFilter(Country country) {
045    addParameter(DatasetSearchParameter.PUBLISHING_COUNTRY, country.getIso2LetterCode());
046  }
047
048  /**
049   * Filters dataset by a country of the geospatial coverage.
050   *
051   * @param country appearing in geospatial coverage
052   */
053  public void addCountryFilter(Country country) {
054    addParameter(DatasetSearchParameter.COUNTRY, country.getIso2LetterCode());
055  }
056
057  /**
058   * Filters dataset by a continent of the geospatial coverage.
059   *
060   * @param continent appearing in geospatial coverage
061   */
062  public void addContinentFilter(Continent continent) {
063    addParameter(DatasetSearchParameter.CONTINENT, continent);
064  }
065
066  /**
067   * Filters datasets by their temporal coverage broken down to decades.
068   *
069   * @param decade the decade given as a 4 digit integer
070   */
071  public void addDecadeFilter(int decade) {
072    addParameter(DatasetSearchParameter.DECADE, decade);
073  }
074
075  public void addHostingOrgFilter(UUID orgKey) {
076    addParameter(DatasetSearchParameter.HOSTING_ORG, orgKey.toString());
077  }
078
079  /**
080   * Filters datasets by a keyword given in EML or as simple, public tags.
081   *
082   * @param keyword a plain keyword e.g. created by Tag.toString()
083   */
084  public void addKeywordFilter(String keyword) {
085    addParameter(DatasetSearchParameter.KEYWORD, keyword);
086  }
087
088  /**
089   * Filters dataset by a tag.
090   *
091   * @param keyword given as a tag
092   */
093  public void addKeywordFilter(Tag keyword) {
094    addParameter(DatasetSearchParameter.KEYWORD, keyword.toString());
095  }
096
097  public void addPublishingOrgFilter(UUID orgKey) {
098    addParameter(DatasetSearchParameter.PUBLISHING_ORG, orgKey.toString());
099  }
100
101  public void addSubTypeFilter(DatasetSubtype subtype) {
102    addParameter(DatasetSearchParameter.SUBTYPE, subtype);
103  }
104
105  public void addTypeFilter(DatasetType type) {
106    addParameter(DatasetSearchParameter.TYPE, type);
107  }
108
109  public void addProjectIdentifier(String identifier) {
110    addParameter(DatasetSearchParameter.PROJECT_ID, identifier);
111  }
112
113  public void addTaxonKey(int taxonKey) {
114    addParameter(DatasetSearchParameter.TAXON_KEY, taxonKey);
115  }
116
117  public void addYear(int year) {
118    addParameter(DatasetSearchParameter.YEAR, year);
119  }
120}