|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.search.Collector org.apache.lucene.search.CachingCollector
public abstract class CachingCollector
Caches all docs, and optionally also scores, coming from
a search, and is then able to replay them to another
collector. You specify the max RAM this class may use.
Once the collection is done, call isCached()
. If
this returns true, you can use replay(org.apache.lucene.search.Collector)
against a
new collector. If it returns false, this means too much
RAM was required and you must instead re-run the original
search.
NOTE: this class consumes 4 (or 8 bytes, if scoring is cached) per collected document. If the result set is large this can easily be a very substantial amount of RAM!
NOTE: this class caches at least 128 documents before checking RAM limits.
See the Lucene contrib/grouping module for more details including a full code example.
Field Summary | |
---|---|
protected int |
base
|
protected List<int[]> |
cachedDocs
|
protected List<org.apache.lucene.search.CachingCollector.SegStart> |
cachedSegs
|
protected int[] |
curDocs
|
protected int |
lastDocBase
|
protected int |
maxDocsToCache
|
protected Collector |
other
|
protected int |
upto
|
Method Summary | |
---|---|
boolean |
acceptsDocsOutOfOrder()
Return true if this collector does not
require the matching docIDs to be delivered in int sort
order (smallest to largest) to Collector.collect(int) . |
static CachingCollector |
create(boolean acceptDocsOutOfOrder,
boolean cacheScores,
double maxRAMMB)
Creates a CachingCollector which does not wrap another collector. |
static CachingCollector |
create(Collector other,
boolean cacheScores,
double maxRAMMB)
Create a new CachingCollector that wraps the given collector and
caches documents and scores up to the specified RAM threshold. |
static CachingCollector |
create(Collector other,
boolean cacheScores,
int maxDocsToCache)
Create a new CachingCollector that wraps the given collector and
caches documents and scores up to the specified max docs threshold. |
boolean |
isCached()
|
abstract void |
replay(Collector other)
Replays the cached doc IDs (and scores) to the given Collector. |
void |
setNextReader(IndexReader reader,
int docBase)
Called before collecting from each IndexReader. |
Methods inherited from class org.apache.lucene.search.Collector |
---|
collect, setScorer |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Collector other
protected final int maxDocsToCache
protected final List<org.apache.lucene.search.CachingCollector.SegStart> cachedSegs
protected final List<int[]> cachedDocs
protected int[] curDocs
protected int upto
protected int base
protected int lastDocBase
Method Detail |
---|
public static CachingCollector create(boolean acceptDocsOutOfOrder, boolean cacheScores, double maxRAMMB)
CachingCollector
which does not wrap another collector.
The cached documents and scores can later be replayed
.
acceptDocsOutOfOrder
- whether documents are allowed to be collected out-of-orderpublic static CachingCollector create(Collector other, boolean cacheScores, double maxRAMMB)
CachingCollector
that wraps the given collector and
caches documents and scores up to the specified RAM threshold.
other
- the Collector to wrap and delegate calls to.cacheScores
- whether to cache scores in addition to document IDs. Note that
this increases the RAM consumed per docmaxRAMMB
- the maximum RAM in MB to consume for caching the documents and
scores. If the collector exceeds the threshold, no documents and
scores are cached.public static CachingCollector create(Collector other, boolean cacheScores, int maxDocsToCache)
CachingCollector
that wraps the given collector and
caches documents and scores up to the specified max docs threshold.
other
- the Collector to wrap and delegate calls to.cacheScores
- whether to cache scores in addition to document IDs. Note that
this increases the RAM consumed per docmaxDocsToCache
- the maximum number of documents for caching the documents and
possible the scores. If the collector exceeds the threshold,
no documents and scores are cached.public boolean acceptsDocsOutOfOrder()
Collector
true
if this collector does not
require the matching docIDs to be delivered in int sort
order (smallest to largest) to Collector.collect(int)
.
Most Lucene Query implementations will visit
matching docIDs in order. However, some queries
(currently limited to certain cases of BooleanQuery
) can achieve faster searching if the
Collector
allows them to deliver the
docIDs out of order.
Many collectors don't mind getting docIDs out of
order, so it's important to return true
here.
acceptsDocsOutOfOrder
in class Collector
public boolean isCached()
public void setNextReader(IndexReader reader, int docBase) throws IOException
Collector
Collector.collect(int)
will correspond to reader.
Add docBase to the current IndexReaders internal document id to re-base ids
in Collector.collect(int)
.
setNextReader
in class Collector
reader
- next IndexReader
IOException
public abstract void replay(Collector other) throws IOException
other.setScorer
as well as scores are not replayed.
IllegalStateException
- if this collector is not cached (i.e., if the RAM limits were too
low for the number of documents + scores to cache).
IllegalArgumentException
- if the given Collect's does not support out-of-order collection,
while the collector passed to the ctor does.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |