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