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;
018:
019: import java.io.Serializable;
020:
021: /**
022: * Mutual operations for hits, for both detached and transactional hits.
023: *
024: * @author kimchy
025: */
026: public interface CompassHitsOperations extends Serializable,
027: Iterable<CompassHit> {
028:
029: /**
030: * Returns the number of hits,
031: *
032: * @return The number of hits.
033: */
034: int getLength();
035:
036: /**
037: * Returns the number of hits,
038: *
039: * @return The number of hits.
040: */
041: int length();
042:
043: /**
044: * Returns the object that maps the n'th hit
045: *
046: * @param n The n'th hit.
047: * @return The object.
048: * @throws CompassException
049: */
050: Object data(int n) throws CompassException;
051:
052: /**
053: * Returns the resource that maps to the n'th hit
054: *
055: * @param n The n'th hit.
056: * @return The resource.
057: * @throws CompassException
058: */
059: Resource resource(int n) throws CompassException;
060:
061: /**
062: * Returns a compass hit wrapper that maps to the n'th hit
063: *
064: * @param n The n'th hit.
065: * @return The hit.
066: * @throws CompassException
067: */
068: CompassHit hit(int n) throws CompassException;
069:
070: /**
071: * Returns a cached highlighted text the maps to the n'th hit.
072: * <p/>
073: * Highlighted text is automatically cached when using {@link CompassHighlighter}
074: * using {@link CompassHits#highlighter(int)}.
075: *
076: * @param n The n'th hit
077: * @return A highlighted text cache associated witht the n'th hit
078: * @throws CompassException
079: */
080: CompassHighlightedText highlightedText(int n)
081: throws CompassException;
082:
083: /**
084: * Returns the score of the n'th hit. Can be a value between 0 and 1,
085: * normalised by the highest scoring hit.
086: *
087: * @param n The n'th hit.
088: * @return The score.
089: * @throws CompassException
090: */
091: float score(int n) throws CompassException;
092:
093: /**
094: * Retrurn the query that resulted in this search hits.
095: */
096: CompassQuery getQuery();
097:
098: /**
099: * Returns a suggested query (based on spell check).
100: *
101: * @see CompassQuery#getSuggestedQuery()
102: */
103: CompassQuery getSuggestedQuery();
104: }
|