FileDocCategorySizeDatePackage
StandardGdataSearcher.javaAPI DocApache Lucene 2.1.04802Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.search

StandardGdataSearcher

public class StandardGdataSearcher extends Object implements GDataSearcher
Standard implementation of {@link org.apache.lucene.gdata.search.GDataSearcher}
author
Simon Willnauer

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

param
searcher - the current lucene searcher instance


                     
       
        if (searcher == null)
            throw new IllegalArgumentException("searcher must not be null");

        this.searcher = searcher;

    
Methods Summary
public voidclose()

see
org.apache.lucene.gdata.search.GDataSearcher#close()

        this.isClosed.set(true);
        this.searcher.decrementRef();

    
protected java.util.ListcollectHits(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 voidflushFilterCache()

        synchronized (queryFilterCache) {
            queryFilterCache.clear();
        }
        
    
public java.util.Listsearch(org.apache.lucene.search.Query query, int hitcount, int offset, java.lang.String feedId)

see
org.apache.lucene.gdata.search.GDataSearcher#search(org.apache.lucene.search.Query, int, int, java.lang.String)

        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);