StandardGdataSearcherpublic class StandardGdataSearcher extends Object implements GDataSearcherStandard implementation of
{@link org.apache.lucene.gdata.search.GDataSearcher} |
Fields Summary |
---|
private final AtomicBoolean | isClosed | private final org.apache.lucene.gdata.utils.ReferenceCounter | searcher | private static final Map | queryFilterCache |
Constructors Summary |
---|
public StandardGdataSearcher(org.apache.lucene.gdata.utils.ReferenceCounter searcher)constructs a new GdataSearcher
if (searcher == null)
throw new IllegalArgumentException("searcher must not be null");
this.searcher = searcher;
|
Methods Summary |
---|
public void | close()
this.isClosed.set(true);
this.searcher.decrementRef();
| protected java.util.List | collectHits(org.apache.lucene.search.Hits hits, int hitcount, int offset)
int hitLength = hits.length();
if (hitLength < offset || hitLength == 0)
return new ArrayList<String>(0);
if (offset > 0)
--offset;
/*
* include the offset
*/
int remainingHits = hitLength - offset;
int returnSize = remainingHits > hitcount ? hitcount : remainingHits;
List<String> retVal = new ArrayList<String>(returnSize);
for (int i = 0; i < returnSize; i++) {
Document doc = hits.doc(offset++);
/*
* the entry id is sufficient to retrieve the entry from the
* storage. the result will be ordered by score (default)
*/
Field field = doc.getField(IndexDocument.FIELD_ENTRY_ID);
retVal.add(i, field.stringValue());
}
return retVal;
| static void | flushFilterCache()
synchronized (queryFilterCache) {
queryFilterCache.clear();
}
| public java.util.List | search(org.apache.lucene.search.Query query, int hitcount, int offset, java.lang.String feedId)
if (hitcount < 0 || offset < 0)
throw new IllegalArgumentException(
"hit count and offset must not be less than 0");
if (this.isClosed.get())
throw new IllegalStateException("Searcher is closed");
if (query == null)
throw new RuntimeException("query is null can not apply search");
if (feedId == null)
throw new IllegalArgumentException("feed id must not be null");
QueryFilter filter = null;
synchronized (queryFilterCache) {
filter = queryFilterCache.get(feedId);
if (filter == null)
filter = new QueryFilter(new TermQuery(new Term(
IndexDocument.FIELD_FEED_ID, feedId)));
queryFilterCache.put(feedId, filter);
}
IndexSearcher indexSearcher = this.searcher.get();
Hits hits = indexSearcher.search(query, filter);
return collectHits(hits, hitcount, offset);
|
|