Refactored to use typed arrays instead of generic lists. (thanks to Otis)

However, the array of objects returned are no longer guaranteed to be unique.
Clients should construct a Set out of the objectResults if uniqueness is required.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150770 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kelvin Tan 2002-05-11 07:01:10 +00:00
parent 06e1cc92d3
commit 5420a95069
1 changed files with 10 additions and 16 deletions

View File

@ -1,13 +1,9 @@
import org.apache.log4j.Category;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Hits;
import search.SearchResultFactory;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import search.SearchResultFactory;
/**
* <p>
@ -27,8 +23,8 @@ import search.SearchResultFactory;
public class SearchResults
{
private static Category cat = Category.getInstance(SearchResults.class);
private List hitsDocuments;
private List objectResults;
private Document[] hitsDocuments;
private Object[] objectResults;
private int totalNumberOfResults;
public SearchResults(Hits hits) throws IOException
@ -38,7 +34,7 @@ public class SearchResults
public SearchResults(Hits hits, int from, int to) throws IOException
{
hitsDocuments = new ArrayList();
hitsDocuments = new Document[hits.length()];
totalNumberOfResults = hits.length();
if (to > totalNumberOfResults)
{
@ -46,7 +42,7 @@ public class SearchResults
}
for (int i = from; i < to; i++)
{
hitsDocuments.add(hits.doc(i));
hitsDocuments[i] = hits.doc(i));
}
}
@ -58,19 +54,17 @@ public class SearchResults
/**
* Obtain the results of the search as objects.
*/
public List getResultsAsObjects()
public Object[] getResultsAsObjects()
{
if (objectResults == null)
{
objectResults = new ArrayList();
for (Iterator it = hitsDocuments.iterator(); it.hasNext();)
objectResults = new Object[hitsDocuments.length];
for (int i = 0; i < hitsDocuments.length; i++)
{
try
{
Object o = SearchResultFactory.
getDocAsObject((Document) it.next());
if (!objectResults.contains(o))
objectResults.add(o);
objectResults[i] = SearchResultFactory.
getDocAsObject(hitsDocuments[i]);
}
catch (Exception e)
{