Skip to content

Commit

Permalink
annotate IndexSearcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Edarke committed Jan 10, 2025
1 parent 1778377 commit 5b7fdf8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.lucene.search.similarities.Similarity;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.Nullable;
import org.apache.lucene.util.automaton.ByteRunAutomaton;

/**
Expand Down Expand Up @@ -198,7 +199,7 @@ public IndexSearcher(IndexReader r) {
*
* @lucene.experimental
*/
public IndexSearcher(IndexReader r, Executor executor) {
public IndexSearcher(IndexReader r, @Nullable Executor executor) {
this(r.getContext(), executor);
}

Expand All @@ -215,7 +216,7 @@ public IndexSearcher(IndexReader r, Executor executor) {
* @see IndexReader#getContext()
* @lucene.experimental
*/
public IndexSearcher(IndexReaderContext context, Executor executor) {
public IndexSearcher(IndexReaderContext context, @Nullable Executor executor) {
assert context.isTopLevel
: "IndexSearcher's ReaderContext must be topLevel for reader " + context.reader();
reader = context.reader();
Expand Down Expand Up @@ -580,7 +581,7 @@ private static void enforceDistinctLeaves(LeafSlice leafSlice) {
* @throws TooManyClauses If a query would exceed {@link IndexSearcher#getMaxClauseCount()}
* clauses.
*/
public TopDocs searchAfter(ScoreDoc after, Query query, int numHits) throws IOException {
public TopDocs searchAfter(@Nullable ScoreDoc after, Query query, int numHits) throws IOException {
final int limit = Math.max(1, reader.maxDoc());
if (after != null && after.doc >= limit) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -713,7 +714,7 @@ public TopFieldDocs searchAfter(
}

private TopFieldDocs searchAfter(
FieldDoc after, Query query, int numHits, Sort sort, boolean doDocScores) throws IOException {
@Nullable FieldDoc after, Query query, int numHits, Sort sort, boolean doDocScores) throws IOException {
final int limit = Math.max(1, reader.maxDoc());
if (after != null && after.doc >= limit) {
throw new IllegalArgumentException(
Expand Down Expand Up @@ -1131,6 +1132,7 @@ public TermStatistics termStatistics(Term term, int docFreq, long totalTermFreq)
*
* @lucene.experimental
*/
@Nullable
public CollectionStatistics collectionStatistics(String field) throws IOException {
assert field != null;
long docCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.lucene.util.Nullable;

/**
* Create a TopFieldCollectorManager which uses a shared hit counter to maintain number of hits and
Expand Down Expand Up @@ -76,7 +77,7 @@ public TopFieldCollectorManager(
* count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit
* count accurate, but this will also make query processing slower.
*/
public TopFieldCollectorManager(Sort sort, int numHits, FieldDoc after, int totalHitsThreshold) {
public TopFieldCollectorManager(Sort sort, int numHits, @Nullable FieldDoc after, int totalHitsThreshold) {
if (totalHitsThreshold < 0) {
throw new IllegalArgumentException(
"totalHitsThreshold must be >= 0, got " + totalHitsThreshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.util.Collection;
import org.apache.lucene.util.Nullable;

/**
* Create a TopScoreDocCollectorManager which uses a shared hit counter to maintain number of hits
Expand Down Expand Up @@ -57,7 +58,7 @@ public class TopScoreDocCollectorManager
*/
@Deprecated
public TopScoreDocCollectorManager(
int numHits, ScoreDoc after, int totalHitsThreshold, boolean supportsConcurrency) {
int numHits, @Nullable ScoreDoc after, int totalHitsThreshold, boolean supportsConcurrency) {
this(numHits, after, totalHitsThreshold);
}

Expand All @@ -82,7 +83,7 @@ public TopScoreDocCollectorManager(
* count of the result will be accurate. {@link Integer#MAX_VALUE} may be used to make the hit
* count accurate, but this will also make query processing slower.
*/
public TopScoreDocCollectorManager(int numHits, ScoreDoc after, int totalHitsThreshold) {
public TopScoreDocCollectorManager(int numHits, @Nullable ScoreDoc after, int totalHitsThreshold) {
if (totalHitsThreshold < 0) {
throw new IllegalArgumentException(
"totalHitsThreshold must be >= 0, got " + totalHitsThreshold);
Expand Down
4 changes: 4 additions & 0 deletions lucene/core/src/java/org/apache/lucene/util/Nullable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.apache.lucene.util;

public @interface Nullable {
}

0 comments on commit 5b7fdf8

Please sign in to comment.