001/*
002 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.registry.search;
017
018
019import org.gbif.api.model.common.paging.Pageable;
020import org.gbif.api.model.common.search.FacetedSearchRequest;
021import org.gbif.api.model.registry.Tag;
022import org.gbif.api.vocabulary.Continent;
023import org.gbif.api.vocabulary.Country;
024import org.gbif.api.vocabulary.DatasetSubtype;
025import org.gbif.api.vocabulary.DatasetType;
026
027import java.util.UUID;
028
029/**
030 * A dataset specific search request with convenience methods to add facet filters.
031 */
032public class DatasetSearchRequest extends FacetedSearchRequest<DatasetSearchParameter> {
033  private Integer highlightContext = -1;
034
035  public DatasetSearchRequest() {
036  }
037
038  public DatasetSearchRequest(Pageable page) {
039    super(page);
040  }
041
042  public DatasetSearchRequest(long offset, int limit) {
043    super(offset, limit);
044  }
045
046  /**
047   * @return the number of characters of the context to show for the highlighted match, including the match itself.
048   */
049  public Integer getHighlightContext() {
050    return highlightContext;
051  }
052
053  public void setHighlightContext(Integer highlightContext) {
054    this.highlightContext = highlightContext;
055  }
056
057  /**
058   * Filters dataset by the owning organizations country.
059   */
060  public void addPublishingCountryFilter(Country country) {
061    addParameter(DatasetSearchParameter.PUBLISHING_COUNTRY, country.getIso2LetterCode());
062  }
063
064  /**
065   * Filters dataset by a country of the geospatial coverage.
066   *
067   * @param country appearing in geospatial coverage
068   */
069  public void addCountryFilter(Country country) {
070    addParameter(DatasetSearchParameter.COUNTRY, country.getIso2LetterCode());
071  }
072
073  /**
074   * Filters dataset by a continent of the geospatial coverage.
075   *
076   * @param continent appearing in geospatial coverage
077   */
078  public void addContinentFilter(Continent continent) {
079    addParameter(DatasetSearchParameter.CONTINENT, continent);
080  }
081
082  /**
083   * Filters datasets by their temporal coverage broken down to decades.
084   *
085   * @param decade the decade given as a 4 digit integer
086   */
087  public void addDecadeFilter(int decade) {
088    addParameter(DatasetSearchParameter.DECADE, decade);
089  }
090
091  public void addHostingOrgFilter(UUID orgKey) {
092    addParameter(DatasetSearchParameter.HOSTING_ORG, orgKey.toString());
093  }
094
095  /**
096   * Filters datasets by a keyword given in EML or as simple, public tags.
097   *
098   * @param keyword a plain keyword e.g. created by Tag.toString()
099   */
100  public void addKeywordFilter(String keyword) {
101    addParameter(DatasetSearchParameter.KEYWORD, keyword);
102  }
103
104  /**
105   * Filters dataset by a tag.
106   *
107   * @param keyword given as a tag
108   */
109  public void addKeywordFilter(Tag keyword) {
110    addParameter(DatasetSearchParameter.KEYWORD, keyword.toString());
111  }
112
113  public void addPublishingOrgFilter(UUID orgKey) {
114    addParameter(DatasetSearchParameter.PUBLISHING_ORG, orgKey.toString());
115  }
116
117  public void addSubTypeFilter(DatasetSubtype subtype) {
118    addParameter(DatasetSearchParameter.SUBTYPE, subtype);
119  }
120
121  public void addTypeFilter(DatasetType type) {
122    addParameter(DatasetSearchParameter.TYPE, type);
123  }
124
125  public void addProjectIdentifier(String identifier) {
126    addParameter(DatasetSearchParameter.PROJECT_ID, identifier);
127  }
128
129  public void addTaxonKey(int taxonKey) {
130    addParameter(DatasetSearchParameter.TAXON_KEY, taxonKey);
131  }
132
133  public void addYear(int year) {
134    addParameter(DatasetSearchParameter.YEAR, year);
135  }
136
137  public void addCategory(String category) {
138    addParameter(DatasetSearchParameter.CATEGORY, category);
139  }
140
141  public void addMachineTagName(String machineTagName) {
142    addParameter(DatasetSearchParameter.MACHINE_TAG_NAME, machineTagName);
143  }
144}