-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOLR-3240: add "spellcheck.collateMaxCollectDocs" for estimating coll…
…ation hit-counts. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1479638 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
8 changed files
with
345 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
solr/core/src/java/org/apache/solr/search/EarlyTerminatingCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.apache.solr.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.AtomicReaderContext; | ||
import org.apache.lucene.search.Collector; | ||
import org.apache.lucene.search.Scorer; | ||
/** | ||
* <p> | ||
* A wrapper {@link Collector} that throws {@link EarlyTerminatingCollectorException}) | ||
* once a specified maximum number of documents are collected. | ||
* </p> | ||
*/ | ||
public class EarlyTerminatingCollector extends Collector { | ||
private int numCollected; | ||
private int lastDocId = -1; | ||
private int maxDocsToCollect; | ||
private Collector delegate; | ||
|
||
/** | ||
* <p> | ||
* Wraps a {@link Collector}, throwing {@link EarlyTerminatingCollectorException} | ||
* once the specified maximum is reached. | ||
* </p> | ||
* @param delegate - the Collector to wrap. | ||
* @param maxDocsToCollect - the maximum number of documents to Collect | ||
* | ||
*/ | ||
public EarlyTerminatingCollector(Collector delegate, int maxDocsToCollect) { | ||
this.delegate = delegate; | ||
this.maxDocsToCollect = maxDocsToCollect; | ||
} | ||
|
||
@Override | ||
public boolean acceptsDocsOutOfOrder() { | ||
return delegate.acceptsDocsOutOfOrder(); | ||
} | ||
|
||
@Override | ||
public void collect(int doc) throws IOException { | ||
delegate.collect(doc); | ||
lastDocId = doc; | ||
numCollected++; | ||
if(numCollected==maxDocsToCollect) { | ||
throw new EarlyTerminatingCollectorException(numCollected, lastDocId); | ||
} | ||
} | ||
@Override | ||
public void setNextReader(AtomicReaderContext context) throws IOException { | ||
delegate.setNextReader(context); | ||
} | ||
@Override | ||
public void setScorer(Scorer scorer) throws IOException { | ||
delegate.setScorer(scorer); | ||
} | ||
public int getNumCollected() { | ||
return numCollected; | ||
} | ||
public void setNumCollected(int numCollected) { | ||
this.numCollected = numCollected; | ||
} | ||
public int getLastDocId() { | ||
return lastDocId; | ||
} | ||
public void setLastDocId(int lastDocId) { | ||
this.lastDocId = lastDocId; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
solr/core/src/java/org/apache/solr/search/EarlyTerminatingCollectorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.apache.solr.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. | ||
*/ | ||
/** | ||
* Thrown by {@link EarlyTerminatingCollector} when the maximum to abort | ||
* the scoring / collection process early, when the specified maximum number | ||
* of documents were collected. | ||
*/ | ||
public class EarlyTerminatingCollectorException extends RuntimeException { | ||
private static final long serialVersionUID = 5939241340763428118L; | ||
private int lastDocId = -1; | ||
private int numberCollected; | ||
|
||
public EarlyTerminatingCollectorException(int numberCollected, int lastDocId) { | ||
this.numberCollected = numberCollected; | ||
this.lastDocId = lastDocId; | ||
} | ||
public int getLastDocId() { | ||
return lastDocId; | ||
} | ||
public void setLastDocId(int lastDocId) { | ||
this.lastDocId = lastDocId; | ||
} | ||
public int getNumberCollected() { | ||
return numberCollected; | ||
} | ||
public void setNumberCollected(int numberCollected) { | ||
this.numberCollected = numberCollected; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.