001: /*
002: * Copyright 2004-2006 the original author or authors.
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:
017: package org.compass.core.support.search;
018:
019: import org.compass.core.CompassHit;
020:
021: /**
022: * The results object returned by
023: * {@link org.compass.core.support.search.CompassSearchHelper} when the search
024: * operation on <code>Compass</code> is executed.
025: * <p>
026: * Holds the time it took to perform the search operation (in milliseconds), an
027: * array of <code>CompassHit</code> (which might be all the hits, or only
028: * paginated hits) and an array of <code>Page</code>s if using the pagination
029: * feature.
030: *
031: * @author kimchy
032: */
033: public class CompassSearchResults {
034:
035: /**
036: * A class which holds the page data if using the pagination feature.
037: *
038: * @author kimchy
039: */
040: public static class Page {
041: private int from;
042:
043: private int to;
044:
045: private int size;
046:
047: private boolean selected;
048:
049: /**
050: * Returns the hit number the page starts from.
051: */
052: public int getFrom() {
053: return from;
054: }
055:
056: /**
057: * Sets the hit number the page starts from.
058: */
059: public void setFrom(int from) {
060: this .from = from;
061: }
062:
063: /**
064: * Returns <code>true</code> if the page is selected, i.e. the results
065: * that are shown are part of the page.
066: */
067: public boolean isSelected() {
068: return selected;
069: }
070:
071: /**
072: * Sets if the page is selected or not.
073: */
074: public void setSelected(boolean selected) {
075: this .selected = selected;
076: }
077:
078: /**
079: * Returns the size of the hits in the page.
080: */
081: public int getSize() {
082: return size;
083: }
084:
085: /**
086: * Sets the size of the hits in the page.
087: */
088: public void setSize(int size) {
089: this .size = size;
090: }
091:
092: /**
093: * Returns the hit number that the page ends at.
094: */
095: public int getTo() {
096: return to;
097: }
098:
099: /**
100: * Sets the hit number that the page ends at.
101: */
102: public void setTo(int to) {
103: this .to = to;
104: }
105: }
106:
107: private CompassHit[] hits;
108:
109: private Page[] pages;
110:
111: private long searchTime;
112:
113: private int totalHits;
114:
115: public CompassSearchResults(CompassHit[] hits, long searchTime,
116: int totalHits) {
117: this .hits = hits;
118: this .searchTime = searchTime;
119: this .totalHits = totalHits;
120: }
121:
122: /**
123: * Returns the hits that resulted from the search operation. Might hold all
124: * the hits (not using pagination) or only the hits that belong to the
125: * selected page (if using pagination).
126: *
127: * @return The hits
128: */
129: public CompassHit[] getHits() {
130: return hits;
131: }
132:
133: /**
134: * Returns the time that it took to perform the search operation (in
135: * milliseconds).
136: *
137: * @return How long it took to perform the serarch in milli-seconds.
138: */
139: public long getSearchTime() {
140: return searchTime;
141: }
142:
143: /**
144: * Returns the total number of hits resulted from this search query.
145: *
146: * @return The total number of hits
147: */
148: public int getTotalHits() {
149: return this .totalHits;
150: }
151:
152: /**
153: * Returns the pages that construct all the results.
154: *
155: * @return The pages that holds all the results
156: */
157: public Page[] getPages() {
158: return pages;
159: }
160:
161: /**
162: * Sets the pages that contruct all the results.
163: *
164: * @param pages
165: */
166: public void setPages(Page[] pages) {
167: this.pages = pages;
168: }
169: }
|