001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.solr.search;
017:
018: /**
019: * <code>DocList</code> represents the result of a query: an ordered list of document ids with optional score.
020: * This list contains a subset of the complete list of documents actually matched: <code>size()</code>
021: * document ids starting at <code>offset()</code>.
022: *
023: * @author yonik
024: * @version $Id: DocList.java 472574 2006-11-08 18:25:52Z yonik $
025: * @since solr 0.9
026: */
027: public interface DocList extends DocSet {
028:
029: /**
030: * Returns the zero based offset of this list within the total ordered list of matches to the query.
031: */
032: public int offset();
033:
034: /**
035: * Returns the number of ids in this list.
036: */
037: public int size();
038:
039: /**
040: * Returns the total number of matches for the search
041: * (as opposed to just the number collected according
042: * to <code>offset()</code> and <code>size()</code>).
043: * Hence it's always true that matches() >= size()
044: * @return number of matches for the search(query & any filters)
045: */
046: public int matches();
047:
048: /***
049: public int getDoc(int pos);
050: ***/
051:
052: // hmmm, what if a different slice could be generated from an existing DocSet
053: // (and was before)...
054: // how to distinguish cached values from logical values?
055: // docSet could represent docs 10-20, but actually contain 0-100
056: // should the big slice be cached independently, and a new class called
057: // DocListSubset be created to refer to a range within the DocList?
058: /**
059: * Get a subset of an existing DocList.
060: * Returns null if not possible.
061: */
062: public DocList subset(int offset, int len);
063:
064: /**
065: * Returns an iterator that may be used to iterate over the documents in this DocList
066: *
067: * <p>
068: * The order of the documents returned by this iterator is based on the
069: * Sort order of the search that produced it. The Scoring information
070: * is meaningful only if <code>hasScores()</code> returns true.
071: * </p>
072: * @see #hasScores
073: */
074: public DocIterator iterator();
075:
076: /** True if scores were retained */
077: public boolean hasScores();
078:
079: /** The maximum score for the search... only valid if
080: * scores were retained (if hasScores()==true)
081: */
082: public float maxScore();
083: }
084:
085: /**** Maybe do this at a higher level (more efficient)
086:
087: class SmartDocSet implements DocSet {
088: static int INITIAL_SIZE=10;
089: static int TRANSITION_SIZE=10;
090:
091: protected BitSet bits;
092: int size;
093:
094: protected int[] arr; // keep small set as an array, or as a hash?
095: protected int arrsize;
096:
097: public SmartDocSet() {
098: if (INITIAL_SIZE>0) {
099: arr=new int[INITIAL_SIZE];
100: } else {
101: bits=new BitSet();
102: }
103: }
104:
105:
106: public void addUnique(int doc) {
107: size++;
108: if (bits != null) {
109: bits.set(doc);
110: }
111: else {
112: if (arrsize<10) {
113: arr[arrsize++]=doc;
114: } else {
115: // TODO: transition to bit set
116: }
117: }
118: };
119:
120: public int size() {
121: return size;
122: }
123: public boolean exists(int docid) {
124: return false;
125: }
126: public DocSet intersection(DocSet other) {
127: return null;
128:
129: }
130: public DocSet union(DocSet other) {
131: return null;
132: }
133: }
134: ***/
|