001/* 002 * Copyright 2016 Anyware Services 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.ametys.cms.search.solr.field; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.ametys.cms.content.indexing.solr.SolrFieldNames; 022import org.ametys.cms.search.SearchField; 023 024/** 025 * Dublin Core search field. 026 */ 027public class DublinCoreSearchField implements SearchField 028{ 029 030 private static final Map<String, String> NAME_TO_FIELD = new HashMap<>(); 031 static 032 { 033 NAME_TO_FIELD.put("title", SolrFieldNames.DC_TITLE); 034 NAME_TO_FIELD.put("creator", SolrFieldNames.DC_CREATOR); 035 NAME_TO_FIELD.put("subject", SolrFieldNames.DC_SUBJECT); 036 NAME_TO_FIELD.put("description", SolrFieldNames.DC_DESCRIPTION); 037 NAME_TO_FIELD.put("publisher", SolrFieldNames.DC_PUBLISHER); 038 NAME_TO_FIELD.put("contributor", SolrFieldNames.DC_CONTRIBUTOR); 039 NAME_TO_FIELD.put("date", SolrFieldNames.DC_DATE); 040 NAME_TO_FIELD.put("type", SolrFieldNames.DC_TYPE); 041 NAME_TO_FIELD.put("format", SolrFieldNames.DC_FORMAT); 042 NAME_TO_FIELD.put("identifier", SolrFieldNames.DC_IDENTIFIER); 043 NAME_TO_FIELD.put("source", SolrFieldNames.DC_SOURCE); 044 NAME_TO_FIELD.put("language", SolrFieldNames.DC_LANGUAGE); 045 NAME_TO_FIELD.put("relation", SolrFieldNames.DC_RELATION); 046 NAME_TO_FIELD.put("coverage", SolrFieldNames.DC_COVERAGE); 047 NAME_TO_FIELD.put("rights", SolrFieldNames.DC_RIGHTS); 048 } 049 050 /** The Dublin Core metadata name. */ 051 protected String _metadata; 052 053 /** 054 * Build a Dublin Core search field. 055 * @param dcMetadata The Dublin Core metadata name. 056 */ 057 public DublinCoreSearchField(String dcMetadata) 058 { 059 if (!NAME_TO_FIELD.containsKey(dcMetadata)) 060 { 061 throw new IllegalArgumentException(dcMetadata + " is not a valid Dublin Core metadata."); 062 } 063 064 _metadata = dcMetadata; 065 } 066 067 @Override 068 public String getName() 069 { 070 return NAME_TO_FIELD.get(_metadata); 071 } 072 073 @Override 074 public String getSortField() 075 { 076 return getName() + "_sort"; 077 } 078 079 @Override 080 public String getFacetField() 081 { 082 return getName() + "_dv"; 083 } 084 085}