001/* 002 * Copyright 2017 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.List; 019 020import org.apache.commons.lang3.StringUtils; 021 022/** 023 * Content generic search field. 024 */ 025public class ContentSearchField extends StringSearchField 026{ 027 /** 028 * Build a content search field. 029 * @param path The field path. 030 */ 031 public ContentSearchField(String path) 032 { 033 super(path); 034 } 035 /** 036 * Build a content search field. 037 * @param joinPaths The join field paths 038 * @param finalPath The final field path. 039 */ 040 public ContentSearchField(List<String> joinPaths, String finalPath) 041 { 042 super(joinPaths, finalPath); 043 } 044 045 @Override 046 public String getJoinedPath() 047 { 048 // As the join must be done until the id field, '_path' is part of the join 049 return _joinPaths != null ? StringUtils.join(_joinPaths, "->") + "->" + _path : ""; 050 } 051 052 @Override 053 public String getSortField() 054 { 055 String sortFieldSuffix = _getSortFieldSuffix(); 056 if (sortFieldSuffix == null) 057 { 058 return null; // not sortable 059 } 060 061 if (isJoined()) 062 { 063 return "join(" + StringUtils.join(_joinPaths, "->") + "," + _path + sortFieldSuffix + ")"; 064 } 065 return _path + sortFieldSuffix; 066 } 067 068 @Override 069 public String getFacetField() 070 { 071 if (isJoined()) 072 { 073 // The join must be done until the id field ! 074 return "id"; 075 } 076 else 077 { 078 return super.getFacetField(); 079 } 080 } 081 082 @Override 083 public String getFacetFunction() 084 { 085 if (isJoined()) 086 { 087 // The join must be done until the id field ! 088 String join = getJoinedPath(); 089 return "join(" + join + ",id)"; 090 } 091 else 092 { 093 return super.getFacetFunction(); 094 } 095 } 096}