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