001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.search.api; 019 020import com.google.common.base.MoreObjects; 021 022import java.util.List; 023 024/** 025 * A pojo encapsulating the parameters of a search 026 * 027 * @author dbernstein 028 */ 029public class SearchParameters { 030 031 private final List<Condition> conditions; 032 033 private final List<Condition.Field> fields; 034 035 private final int offset; 036 037 private final int maxResults; 038 039 private final Condition.Field orderBy; 040 041 private final String order; 042 043 private final boolean includeTotalResultCount; 044 /** 045 * Constructoor 046 * 047 * @param fields The fields to be returned in the results 048 * @param conditions The conditions 049 * @param maxResults The max results 050 * @param offset The offset 051 * @param orderBy The field by which to order the results 052 * @param order The order: ie "asc" or "desc" 053 * @param includeTotalResultCount A flag indicating whether or not to return the total result count. 054 */ 055 public SearchParameters(final List<Condition.Field> fields, final List<Condition> conditions, final int maxResults, 056 final int offset, final Condition.Field orderBy, final String order, 057 final boolean includeTotalResultCount) { 058 this.fields = fields; 059 this.conditions = conditions; 060 this.maxResults = maxResults; 061 this.offset = offset; 062 this.orderBy = orderBy; 063 this.order = order; 064 this.includeTotalResultCount = includeTotalResultCount; 065 } 066 067 /** 068 * The offset (zero-based) 069 * 070 * @return 071 */ 072 public int getOffset() { 073 return offset; 074 } 075 076 /** 077 * The max number of results to return 078 * 079 * @return 080 */ 081 public int getMaxResults() { 082 return maxResults; 083 } 084 085 /** 086 * The conditions limiting the search 087 * 088 * @return 089 */ 090 public List<Condition> getConditions() { 091 return conditions; 092 } 093 094 /** 095 * Returns the list of fields to display in the results. 096 * 097 * @return 098 */ 099 public List<Condition.Field> getFields() { 100 return fields; 101 } 102 103 /** 104 * Returns the field by which to order the results. 105 * 106 * @return 107 */ 108 public Condition.Field getOrderBy() { 109 return orderBy; 110 } 111 112 /** 113 * Returns the order direction (asc or desc) of the results. 114 * 115 * @return 116 */ 117 public String getOrder() { 118 return order; 119 } 120 121 /** 122 * Returns flag indicating whether or not to include the total result count in the query results. 123 * @return 124 */ 125 public boolean isIncludeTotalResultCount() { 126 return includeTotalResultCount; 127 } 128 129 @Override 130 public String toString() { 131 final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this); 132 helper.add("conditions", conditions); 133 helper.add("maxResults", maxResults); 134 helper.add("offset", offset); 135 helper.add("fields", fields); 136 helper.add("orderBy", orderBy); 137 helper.add("order", order); 138 helper.add("includeTotalResultCount", includeTotalResultCount); 139 return helper.toString(); 140 } 141}