001/* 002 * Copyright 2015 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.query; 017 018import java.util.Arrays; 019 020import org.ametys.cms.content.indexing.solr.SolrFieldNames; 021 022/** 023 * Represents a {@link Query} testing if an object possesses one or more tags. 024 */ 025public class TagQuery extends AbstractMultivaluedQuery<String> 026{ 027 /** 028 * Build a TagQuery. 029 * @param value the tag id to test. 030 */ 031 public TagQuery(String value) 032 { 033 this(new String[] {value}); 034 } 035 036 /** 037 * Build a TagQuery. 038 * @param values the tag IDs to test. 039 */ 040 public TagQuery(String... values) 041 { 042 this(Operator.EQ, values); 043 } 044 045 /** 046 * Build a TagQuery. 047 * @param operator the operator. 048 * @param value the tag id to test. 049 */ 050 public TagQuery(Operator operator, String value) 051 { 052 this(operator, new String[] {value}); 053 } 054 055 /** 056 * Build a TagQuery. 057 * @param operator the operator. 058 * @param values the tag IDs to test. 059 */ 060 public TagQuery(Operator operator, String... values) 061 { 062 this(operator, false, values); 063 } 064 065 /** 066 * Build a TagQuery. 067 * @param operator the operator. 068 * @param descendantAutoposting true to enable descendant autoposting (parent tags are found), false otherwise. 069 * @param value the tag id to test. 070 */ 071 public TagQuery(Operator operator, boolean descendantAutoposting, String value) 072 { 073 this(operator, descendantAutoposting, new String[] {value}); 074 } 075 076 /** 077 * Build a TagQuery. 078 * @param operator the operator. 079 * @param descendantAutoposting true to enable descendant autoposting (parent tags are found), false otherwise. 080 * @param values the tag IDs to test. 081 */ 082 public TagQuery(Operator operator, boolean descendantAutoposting, String... values) 083 { 084 this(operator, descendantAutoposting, LogicalOperator.OR, values); 085 } 086 087 /** 088 * Build a TagQuery. 089 * @param operator the operator. The operator is applied to each value individually. 090 * For instance, if operator is {@link Query.Operator#NE NE} and logicalOperator is 091 * {@link Query.LogicalOperator#OR OR}, then the Query represents: <code>(NOT A) OR (NOT B) ...</code> 092 * @param descendantAutoposting true to enable descendant autoposting (parent tags are found), false otherwise. 093 * @param logicalOperator the logical operator. 094 * @param values the tag IDs to test. 095 */ 096 public TagQuery(Operator operator, boolean descendantAutoposting, LogicalOperator logicalOperator, String... values) 097 { 098 super(descendantAutoposting ? SolrFieldNames.ALL_TAGS : SolrFieldNames.TAGS, operator, logicalOperator, values != null ? Arrays.asList(values) : null); 099 } 100}