@@ -0,0 +1,2229 @@
+import org.apache.log4j.Category;%0Aimport org.apache.lucene.document.Document;%0Aimport org.apache.lucene.search.Hits;%0A%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A%0Aimport search.SearchResultFactory;%0A%0A/**%0A * %3Cp%3E%0A * Encapsulates the results of a search. After a SearchResults has%0A * been constructed from a Hits object, the IndexSearcher can be%0A * safely closed.%0A * %3C/p%3E%0A * %3Cp%3E%0A * SearchResults also provides a way of retrieving Java objects from%0A * Documents (via %7B@link search.SearchResultsFactory%7D).%0A * %3C/p%3E%0A * %3Cp%3E%0A * %3Cb%3ENote that this implementation uses code from%0A * /projects/appex/search.%3C/b%3E%0A * %3C/p%3E%0A */%0Apublic class SearchResults%0A%7B%0A    private static Category cat = Category.getInstance(SearchResults.class);%0A    private List hitsDocuments;%0A    private List objectResults;%0A    private int totalNumberOfResults;%0A%0A    public SearchResults(Hits hits) throws IOException%0A    %7B%0A        this(hits, 0, hits.length());%0A    %7D%0A%0A    public SearchResults(Hits hits, int from, int to) throws IOException%0A    %7B%0A        hitsDocuments = new ArrayList();%0A        totalNumberOfResults = hits.length();%0A        if (to %3E totalNumberOfResults)%0A        %7B%0A            to = totalNumberOfResults;%0A        %7D%0A        for (int i = from; i %3C to; i++)%0A        %7B%0A            hitsDocuments.add(hits.doc(i));%0A        %7D%0A    %7D%0A%0A    public int getTotalNumberOfResults()%0A    %7B%0A        return totalNumberOfResults;%0A    %7D%0A%0A    /**%0A     * Obtain the results of the search as objects.%0A     */%0A    public List getResultsAsObjects()%0A    %7B%0A        if (objectResults == null)%0A        %7B%0A            objectResults = new ArrayList();%0A            for (Iterator it = hitsDocuments.iterator(); it.hasNext();)%0A            %7B%0A                try%0A                %7B%0A                    Object o = SearchResultFactory.%0A                            getDocAsObject((Document) it.next());%0A                    if (!objectResults.contains(o))%0A                        objectResults.add(o);%0A                %7D%0A                catch (Exception e)%0A                %7B%0A                    cat.error(%22Error instantiating an object from a document.%22, e);%0A                %7D%0A            %7D%0A        %7D%0A        return objectResults;%0A    %7D%0A%7D%0A

An object to encapsulate the results of a search.