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.checklistbank.search; 017 018import org.gbif.api.model.common.paging.Pageable; 019import org.gbif.api.model.common.search.FacetedSearchRequest; 020import org.gbif.api.vocabulary.Habitat; 021import org.gbif.api.vocabulary.NameUsageIssue; 022import org.gbif.api.vocabulary.NomenclaturalStatus; 023import org.gbif.api.vocabulary.Origin; 024import org.gbif.api.vocabulary.Rank; 025import org.gbif.api.vocabulary.TaxonomicStatus; 026import org.gbif.api.vocabulary.ThreatStatus; 027 028import java.util.UUID; 029 030/** 031 * A name usage specific search request with convenience methods to add enum based search filters. 032 * By default the query q is send to all available query fields. 033 * Highlighting by default works for descriptions and vernacular names - if turned on. 034 */ 035@SuppressWarnings("unused") 036public class NameUsageSearchRequest extends FacetedSearchRequest<NameUsageSearchParameter> { 037 private boolean extended = true; 038 private Integer highlightContext = 100; 039 040 public enum NameUsageQueryField implements QueryField { 041 SCIENTIFIC, 042 VERNACULAR, 043 DESCRIPTION 044 } 045 046 public NameUsageSearchRequest() { 047 } 048 049 public NameUsageSearchRequest(Pageable page) { 050 super(page); 051 } 052 053 public NameUsageSearchRequest(long offset, int limit) { 054 super(offset, limit); 055 } 056 057 /** 058 * @return the number of characters of the context to show for the highlighted match, including the match itself. 059 */ 060 public Integer getHighlightContext() { 061 return highlightContext; 062 } 063 064 public void setHighlightContext(Integer highlightContext) { 065 this.highlightContext = highlightContext; 066 } 067 068 /** 069 * Allows to request an extended search object with the larger list properties: 070 * <ul> 071 * <li>habitats</li> 072 * <li>nomenclaturalStatus</li> 073 * <li>threatStatuses</li> 074 * <li>descriptions</li> 075 * <li>vernacularNames</li> 076 * </ul> 077 * 078 * If extended=false and highlighting is activated, the highlighted matches will still be added to the extended properties. 079 * In that case only the matched parts are shown, e.g. just the one vernacular name that matched. 080 * 081 * @return if true request the extended search model 082 */ 083 public boolean isExtended() { 084 return extended; 085 } 086 087 public void setExtended(boolean extended) { 088 this.extended = extended; 089 } 090 091 public void addChecklistFilter(UUID datasetKey) { 092 addParameter(NameUsageSearchParameter.DATASET_KEY, datasetKey.toString()); 093 } 094 095 public void addExtinctFilter(boolean isExtinct) { 096 addParameter(NameUsageSearchParameter.IS_EXTINCT, String.valueOf(isExtinct)); 097 } 098 099 public void addHigherTaxonFilter(int taxonKey) { 100 addParameter(NameUsageSearchParameter.HIGHERTAXON_KEY, taxonKey); 101 } 102 103 public void addHabitatFilter(Habitat habitat) { 104 addParameter(NameUsageSearchParameter.HABITAT, habitat); 105 } 106 107 public void addRankFilter(Rank rank) { 108 addParameter(NameUsageSearchParameter.RANK, rank); 109 } 110 111 public void addTaxonomicStatusFilter(TaxonomicStatus status) { 112 addParameter(NameUsageSearchParameter.STATUS, status); 113 } 114 115 public void addTaxonomicStatusFilter(NomenclaturalStatus nomenclaturalStatus) { 116 addParameter(NameUsageSearchParameter.NOMENCLATURAL_STATUS, nomenclaturalStatus); 117 } 118 119 public void addThreatStatusFilter(ThreatStatus threat) { 120 addParameter(NameUsageSearchParameter.THREAT, threat); 121 } 122 123 public void addIssueFilter(NameUsageIssue issue) { 124 addParameter(NameUsageSearchParameter.ISSUE, issue); 125 } 126 127 public void addOriginFilter(Origin origin) { 128 addParameter(NameUsageSearchParameter.ORIGIN, origin); 129 } 130 131}