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    /**
044     * Constructoor
045     *
046     * @param fields     The fields to be returned in the results
047     * @param conditions The conditions
048     * @param maxResults The max results
049     * @param offset     The offset
050     * @param orderBy    The field by which to order the results
051     * @param order      The order: ie "asc" or "desc"
052     */
053    public SearchParameters(final List<Condition.Field> fields, final List<Condition> conditions, final int maxResults,
054                            final int offset, final Condition.Field orderBy, final String order) {
055        this.fields = fields;
056        this.conditions = conditions;
057        this.maxResults = maxResults;
058        this.offset = offset;
059        this.orderBy = orderBy;
060        this.order = order;
061    }
062
063    /**
064     * The offset (zero-based)
065     *
066     * @return
067     */
068    public int getOffset() {
069        return offset;
070    }
071
072    /**
073     * The max number of results to return
074     *
075     * @return
076     */
077    public int getMaxResults() {
078        return maxResults;
079    }
080
081    /**
082     * The conditions limiting the search
083     *
084     * @return
085     */
086    public List<Condition> getConditions() {
087        return conditions;
088    }
089
090    /**
091     * Returns the list of fields to display in the results.
092     *
093     * @return
094     */
095    public List<Condition.Field> getFields() {
096        return fields;
097    }
098
099    /**
100     * Returns the field by which to order the results.
101     *
102     * @return
103     */
104    public Condition.Field getOrderBy() {
105        return orderBy;
106    }
107
108    /**
109     * Returns the order direction (asc or desc) of the results.
110     *
111     * @return
112     */
113    public String getOrder() {
114        return order;
115    }
116
117    @Override
118    public String toString() {
119        final MoreObjects.ToStringHelper helper = MoreObjects.toStringHelper(this);
120        helper.add("conditions", conditions);
121        helper.add("maxResults", maxResults);
122        helper.add("offset", offset);
123        helper.add("fields", fields);
124        helper.add("orderBy", orderBy);
125        helper.add("order", order);
126        return helper.toString();
127    }
128}