001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.search.api;
007
008import com.google.common.base.MoreObjects;
009
010import java.util.List;
011
012/**
013 * A pojo encapsulating the parameters of a search
014 *
015 * @author dbernstein
016 */
017public class SearchParameters {
018
019    private final List<Condition> conditions;
020
021    private final List<Condition.Field> fields;
022
023    private final int offset;
024
025    private final int maxResults;
026
027    private final Condition.Field orderBy;
028
029    private final String order;
030
031    private final boolean includeTotalResultCount;
032    /**
033     * Constructoor
034     *
035     * @param fields     The fields to be returned in the results
036     * @param conditions The conditions
037     * @param maxResults The max results
038     * @param offset     The offset
039     * @param orderBy    The field by which to order the results
040     * @param order      The order: ie "asc" or "desc"
041     * @param includeTotalResultCount A flag indicating whether or not to return the total result count.
042     */
043    public SearchParameters(final List<Condition.Field> fields, final List<Condition> conditions, final int maxResults,
044                            final int offset, final Condition.Field orderBy, final String order,
045                            final boolean includeTotalResultCount) {
046        this.fields = fields;
047        this.conditions = conditions;
048        this.maxResults = maxResults;
049        this.offset = offset;
050        this.orderBy = orderBy;
051        this.order = order;
052        this.includeTotalResultCount = includeTotalResultCount;
053    }
054
055    /**
056     * The offset (zero-based)
057     *
058     * @return
059     */
060    public int getOffset() {
061        return offset;
062    }
063
064    /**
065     * The max number of results to return
066     *
067     * @return
068     */
069    public int getMaxResults() {
070        return maxResults;
071    }
072
073    /**
074     * The conditions limiting the search
075     *
076     * @return
077     */
078    public List<Condition> getConditions() {
079        return conditions;
080    }
081
082    /**
083     * Returns the list of fields to display in the results.
084     *
085     * @return
086     */
087    public List<Condition.Field> getFields() {
088        return fields;
089    }
090
091    /**
092     * Returns the field by which to order the results.
093     *
094     * @return
095     */
096    public Condition.Field getOrderBy() {
097        return orderBy;
098    }
099
100    /**
101     * Returns the order direction (asc or desc) of the results.
102     *
103     * @return
104     */
105    public String getOrder() {
106        return order;
107    }
108
109    /**
110     * Returns flag indicating whether or not to include the total result count in the query results.
111     * @return
112     */
113    public boolean isIncludeTotalResultCount() {
114        return includeTotalResultCount;
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        helper.add("includeTotalResultCount", includeTotalResultCount);
127        return helper.toString();
128    }
129}