001/*
002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others.
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 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id: ResultSet.java 28480 2008-01-04 14:04:49Z sfermigier $
020 */
021
022package org.nuxeo.ecm.core.search.api.client.search.results;
023
024import java.util.List;
025
026import org.nuxeo.ecm.core.search.api.client.SearchException;
027
028/**
029 * Result set.
030 *
031 * @author <a href="mailto:ja@nuxeo.com">Julien Anguenot</a>
032 */
033public interface ResultSet extends List<ResultItem> {
034
035    String ALWAYS_DETACH_SEARCH_RESULTS_KEY = "org.nuxeo.ecm.core.search.alwaysDetachResults";
036
037    /**
038     * Returns the current offset for this result set.
039     *
040     * @return the offset as an integer.
041     */
042    int getOffset();
043
044    /**
045     * Returns the amount of results from offset requested.
046     *
047     * @return the amount of results from offset requested.
048     */
049    int getRange();
050
051    /**
052     * Returns the total number of hits this resultset comes from.
053     *
054     * @return an integer value
055     */
056    int getTotalHits();
057
058    /**
059     * Returns the amount of actual matching results.
060     * <p>
061     * This is in contrast to getRange() that returns the maximum number of results per page.
062     *
063     * @return the amount of actual matching results.
064     */
065    int getPageHits();
066
067    /**
068     * Replays the exact same query.
069     *
070     * @return a new, updated ResultSet
071     * @throws SearchException
072     */
073    ResultSet replay() throws SearchException;
074
075    /**
076     * Replays the same query with new offset and range.
077     *
078     * @param offset the new offset
079     * @param range the new range
080     * @return a new, updated ResultSet
081     * @throws SearchException
082     */
083    ResultSet replay(int offset, int range) throws SearchException;
084
085    /**
086     * Computes the next page by replaying the exact same request.
087     *
088     * @return the next computed page or null if there is none.
089     * @throws SearchException
090     */
091    ResultSet nextPage() throws SearchException;
092
093    /**
094     * Goes to requested page.
095     *
096     * @param page the page to go to
097     * @return the next computed page or null if there is none.
098     * @throws SearchException
099     */
100    ResultSet goToPage(int page) throws SearchException;
101
102    /**
103     * Is there another page available?
104     *
105     * @return true if next page available / false if not.
106     */
107    boolean hasNextPage();
108
109    /**
110     * Is this result set the first page of results?
111     *
112     * @return true if first page / false of not.
113     */
114    boolean isFirstPage();
115
116    /**
117     * Computes the page number among the total set of results.
118     *
119     * @return the page number
120     */
121    int getPageNumber();
122
123}