X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java diff --git a/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java b/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java new file mode 100644 index 0000000..76f9b71 --- /dev/null +++ b/lucene-java-3.5.0/lucene/src/java/org/apache/lucene/search/TopFieldCollector.java @@ -0,0 +1,999 @@ +package org.apache.lucene.search; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.IOException; + +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.search.FieldValueHitQueue.Entry; +import org.apache.lucene.util.PriorityQueue; + +/** + * A {@link Collector} that sorts by {@link SortField} using + * {@link FieldComparator}s. + *
+ * See the {@link #create(org.apache.lucene.search.Sort, int, boolean, boolean, boolean, boolean)} method + * for instantiating a TopFieldCollector. + * + * @lucene.experimental + */ +public abstract class TopFieldCollector extends TopDocsCollectorNOTE: The instances returned by this method
+ * pre-allocate a full array of length
+ * numHits
.
+ *
+ * @param sort
+ * the sort criteria (SortFields).
+ * @param numHits
+ * the number of results to collect.
+ * @param fillFields
+ * specifies whether the actual field values should be returned on
+ * the results (FieldDoc).
+ * @param trackDocScores
+ * specifies whether document scores should be tracked and set on the
+ * results. Note that if set to false, then the results' scores will
+ * be set to Float.NaN. Setting this to true affects performance, as
+ * it incurs the score computation on each competitive result.
+ * Therefore if document scores are not required by the application,
+ * it is recommended to set it to false.
+ * @param trackMaxScore
+ * specifies whether the query's maxScore should be tracked and set
+ * on the resulting {@link TopDocs}. Note that if set to false,
+ * {@link TopDocs#getMaxScore()} returns Float.NaN. Setting this to
+ * true affects performance as it incurs the score computation on
+ * each result. Also, setting this true automatically sets
+ * trackDocScores
to true as well.
+ * @param docsScoredInOrder
+ * specifies whether documents are scored in doc Id order or not by
+ * the given {@link Scorer} in {@link #setScorer(Scorer)}.
+ * @return a {@link TopFieldCollector} instance which will sort the results by
+ * the sort criteria.
+ * @throws IOException
+ */
+ public static TopFieldCollector create(Sort sort, int numHits,
+ boolean fillFields, boolean trackDocScores, boolean trackMaxScore,
+ boolean docsScoredInOrder)
+ throws IOException {
+ if (sort.fields.length == 0) {
+ throw new IllegalArgumentException("Sort must contain at least one field");
+ }
+
+ if (numHits <= 0) {
+ throw new IllegalArgumentException("numHits must be > 0; please use TotalHitCountCollector if you just need the total hit count");
+ }
+
+ FieldValueHitQueue