com.sun.labs.minion.retrieval
Class ResultSetImpl

java.lang.Object
  extended by com.sun.labs.minion.retrieval.ResultSetImpl
All Implemented Interfaces:
ResultSet

public class ResultSetImpl
extends java.lang.Object
implements ResultSet

An implementation of the results set interface.


Nested Class Summary
 class ResultSetImpl.AGDocs
           
 
Field Summary
protected  CollectionStats cs
          The statistics for the collection.
protected  SearchEngine e
          The search engine that is creating the results set.
protected  HLPipeline hlp
          A pipeline that can be used for highlighting documents from this set.
protected static java.lang.String logTag
           
protected  QueryConfig qc
          The configuration used for the query that generated this results set.
protected  QueryElement query
          The query, as provided by tmhe user.
protected  long queryTime
          The time spent parsing and evaluating the query, in milliseconds.
protected  java.util.List<ArrayGroup> results
          The results of the search: a list of ArrayGroups.
protected  ResultsFilter rf
          A results filter to use when getting results.
protected  SortSpec sortSpec
          The sorting specification for this query.
 
Constructor Summary
ResultSetImpl(QueryElement query, QueryConfig qc, QueryStats qs, java.util.List partitions, SearchEngine e)
          Creates a result set for the given query by evaluating the query.
ResultSetImpl(ResultSetImpl parent, ResultSetImpl.AGDocs[] docs)
          Constructs a partial result set from the docs passed in.
ResultSetImpl(SearchEngine e)
          Creates an empty result set.
ResultSetImpl(SearchEngine e, QueryConfig qc, java.util.List results)
          Creates a result set from a list of groups.
ResultSetImpl(SearchEngine e, java.lang.String spec, java.util.List results)
          Creates a result set from a list of groups.
 
Method Summary
 java.util.Set<ResultsCluster> cluster(int k)
          Clusters the results into this set into a number of clusters.
 java.util.Set<ResultsCluster> cluster(java.lang.String field, int k)
          Clusters the results into this set into a number of clusters.
 ResultSet difference(ResultSet rs)
          Computes the difference of this result set and another result set.
 java.util.List<Result> getAllResults(boolean sorted)
          Gets all of the query results in the set.
 java.util.List<Result> getAllResults(boolean sorted, ResultsFilter rf)
          Gets all of the query results in the set.
 SearchEngine getEngine()
          Gets the search engine that generated this results set.
 HLPipeline getHLPipeline()
          Gets the highlighting pipeline.
 int getNumDocs()
          Gets the number of documents that are in the whole index.
 QueryStats getQueryStats()
          Gets the statistics for the query that generated this set.
 long getQueryTime()
          Gets the amount of time that it took to evaluate the query, in milliseconds.
 java.util.List<Result> getResults(int start, int n)
          Gets a subset of the query results stored in this set.
 java.util.List<Result> getResults(int start, int n, ResultsFilter rf)
          Gets a subset of the query results stored in this set.
 java.util.List<Result> getResultsForScoredField(int start, int n, java.lang.String field, java.lang.Object value, java.lang.String scoreField)
          Gets the results from this result set ranked using a score field that is associated with another field.
 java.util.Set<ResultsCluster> groupBy(java.lang.String field, boolean ignoreCase)
          Groups the results in this set into a number of clusters.
 ResultSet intersect(ResultSet rs)
          Computes the intersection of this result set with another result set.
 ResultSetImpl.AGDocs newAGDocs(ArrayGroup ag)
           
 boolean querySyntaxError()
          Indicates whether the query contained a syntax error.
 java.util.Iterator<ArrayGroup> resultsIterator()
          Gets an iterator for the per-partition results.
 boolean same(ResultSetImpl other)
          A method to test whether two result sets are the same.
 void setQueryStats(QueryStats qs)
           
 void setResultsFilter(ResultsFilter rf)
          Sets the results filter that will be used to decide whether results should be returned from this set.
 void setScoreModifier(ScoreModifier sm)
          Sets the score modifier that will be used to modify the scores of the documents returned from this set.
 void setSortSpec(java.lang.String sortSpec)
          Sets the sorting specification used by this result set.
 int size()
          Gets the size of the results set, that is, the number of documents that matched the query.
 ResultSet union(ResultSet rs)
          Computes the intersection of this result set with another result set.
 ResultSet weight(float w)
          Weights the results in this set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

query

protected QueryElement query
The query, as provided by tmhe user.


e

protected SearchEngine e
The search engine that is creating the results set.


qc

protected QueryConfig qc
The configuration used for the query that generated this results set.


cs

protected CollectionStats cs
The statistics for the collection.


sortSpec

protected SortSpec sortSpec
The sorting specification for this query.


rf

protected ResultsFilter rf
A results filter to use when getting results.


results

protected java.util.List<ArrayGroup> results
The results of the search: a list of ArrayGroups.


hlp

protected HLPipeline hlp
A pipeline that can be used for highlighting documents from this set.


queryTime

protected long queryTime
The time spent parsing and evaluating the query, in milliseconds.


logTag

protected static java.lang.String logTag
Constructor Detail

ResultSetImpl

public ResultSetImpl(SearchEngine e)
Creates an empty result set.


ResultSetImpl

public ResultSetImpl(QueryElement query,
                     QueryConfig qc,
                     QueryStats qs,
                     java.util.List partitions,
                     SearchEngine e)
Creates a result set for the given query by evaluating the query.

Parameters:
query - The query typed by the user. query.
e - The engine against which we will run the query.
qs - The statistics to accumulate for this query.
qc - The query configuration for this query.
partitions - The partitions against which we will run the query.

ResultSetImpl

public ResultSetImpl(ResultSetImpl parent,
                     ResultSetImpl.AGDocs[] docs)
Constructs a partial result set from the docs passed in.

Parameters:
parent - the full result set that this is a subsest of
docs - the docs to be included in this subset

ResultSetImpl

public ResultSetImpl(SearchEngine e,
                     QueryConfig qc,
                     java.util.List results)
Creates a result set from a list of groups.


ResultSetImpl

public ResultSetImpl(SearchEngine e,
                     java.lang.String spec,
                     java.util.List results)
Creates a result set from a list of groups.

Method Detail

getEngine

public SearchEngine getEngine()
Gets the search engine that generated this results set.

Specified by:
getEngine in interface ResultSet
Returns:
the search engine that generated this result set.

setSortSpec

public void setSortSpec(java.lang.String sortSpec)
Description copied from interface: ResultSet
Sets the sorting specification used by this result set.

Specified by:
setSortSpec in interface ResultSet
Parameters:
sortSpec - a sorting specification for this result set.

setResultsFilter

public void setResultsFilter(ResultsFilter rf)
Description copied from interface: ResultSet
Sets the results filter that will be used to decide whether results should be returned from this set.

Specified by:
setResultsFilter in interface ResultSet
Parameters:
rf - the results filter to use
See Also:
ResultsFilter, CompositeResultsFilter

setScoreModifier

public void setScoreModifier(ScoreModifier sm)
Description copied from interface: ResultSet
Sets the score modifier that will be used to modify the scores of the documents returned from this set.

Specified by:
setScoreModifier in interface ResultSet
Parameters:
sm - the score modifier to use

getResultsForScoredField

public java.util.List<Result> getResultsForScoredField(int start,
                                                       int n,
                                                       java.lang.String field,
                                                       java.lang.Object value,
                                                       java.lang.String scoreField)
                                                throws SearchEngineException
Gets the results from this result set ranked using a score field that is associated with another field. This is useful, for example, when trying to sort a set of results by a classifier confidence score. We can't use a standard sorting specification to do this because it always uses the first value for a field, which may not be the right one.

Parameters:
start - the position in the ranked list to start getting results
n - the number of results to return
field - the field containing the values that the search was done with
value - the value that we searched for in the field
scoreField - the field containing the scores associated with the field
Returns:
a list of the results with the highest score in the score field corresponding to the position of the value in the given field. If the same value is stored more than once in the given field, the first associated score is used for ranking.
Throws:
SearchEngineException - if there is any exception getting the results

getResults

public java.util.List<Result> getResults(int start,
                                         int n)
                                  throws SearchEngineException
Gets a subset of the query results stored in this set.

Specified by:
getResults in interface ResultSet
Parameters:
start - The position in the set to start getting results, indexed from 0.
n - The number of results to get. Note that you may get less than this number of results if there are insufficient results in the set.
Returns:
A list of Result instances containing the search results.
Throws:
SearchEngineException - if there is some error getting the results.

getResults

public java.util.List<Result> getResults(int start,
                                         int n,
                                         ResultsFilter rf)
                                  throws SearchEngineException
Gets a subset of the query results stored in this set.

Specified by:
getResults in interface ResultSet
Parameters:
start - The position in the set to start getting results, indexed from 0.
n - The number of results to get. Note that you may get less than this number of results if there are insufficient results in the set.
rf - a filter that will be used to determine whether results should be put on the heap or not.
Returns:
A list of Result instances containing the search results.
Throws:
SearchEngineException - if there is some error getting the results.

getAllResults

public java.util.List<Result> getAllResults(boolean sorted)
                                     throws SearchEngineException
Gets all of the query results in the set. Note that this list may be very large!

Specified by:
getAllResults in interface ResultSet
Parameters:
sorted - If true, then the results will be sorted according to the sorting specification that was provided with the query. If false, then the results will be returned in an arbitrary order.
Returns:
A list of all the results in the set.
Throws:
SearchEngineException - if there is any error processing the result set

getAllResults

public java.util.List<Result> getAllResults(boolean sorted,
                                            ResultsFilter rf)
                                     throws SearchEngineException
Gets all of the query results in the set. Note that this list may be very large!

Specified by:
getAllResults in interface ResultSet
Parameters:
sorted - If true, then the results will be sorted according to the sorting specification that was provided with the query. If false, then the results will be returned in an arbitrary order.
rf - a filter to use to decide which results from the search should be added to the list. If this is null, then no filter will be applied.
Returns:
A list of all the results in the set.
Throws:
SearchEngineException - if there is any error processing the result set

setQueryStats

public void setQueryStats(QueryStats qs)

getQueryStats

public QueryStats getQueryStats()
Description copied from interface: ResultSet
Gets the statistics for the query that generated this set.

Specified by:
getQueryStats in interface ResultSet
Returns:
the query statistics for the query that generated this set.

querySyntaxError

public boolean querySyntaxError()
Indicates whether the query contained a syntax error.

Specified by:
querySyntaxError in interface ResultSet
Returns:
true if there was such an error, false otherwise.

size

public int size()
Gets the size of the results set, that is, the number of documents that matched the query. If this number is 0, it may be worthwhile to see if the reason is that there was a syntax error in the query.

Specified by:
size in interface ResultSet
Returns:
The number of documents matching the query.
See Also:
querySyntaxError()

getHLPipeline

public HLPipeline getHLPipeline()
Gets the highlighting pipeline.


getNumDocs

public int getNumDocs()
Gets the number of documents that are in the whole index.

Specified by:
getNumDocs in interface ResultSet
Returns:
the number of documents in the entire collection

getQueryTime

public long getQueryTime()
Gets the amount of time that it took to evaluate the query, in milliseconds.

Specified by:
getQueryTime in interface ResultSet
Returns:
the amount of time that it took to evaluate this query, in milliseconds

resultsIterator

public java.util.Iterator<ArrayGroup> resultsIterator()
Gets an iterator for the per-partition results. This is in the implementation only, not the interface!


newAGDocs

public ResultSetImpl.AGDocs newAGDocs(ArrayGroup ag)

cluster

public java.util.Set<ResultsCluster> cluster(int k)
                                      throws SearchEngineException
Description copied from interface: ResultSet
Clusters the results into this set into a number of clusters. The algorithm used depends on how the engine that generated this set of results is configured.

Specified by:
cluster in interface ResultSet
Parameters:
k - the maximum number of clusters to return
Returns:
a set of clusters containing the results in this set. The number of clusters returned may be less than or equal to k
Throws:
SearchEngineException - if there are any errors generating the clusters
See Also:
ResultsCluster

cluster

public java.util.Set<ResultsCluster> cluster(java.lang.String field,
                                             int k)
                                      throws SearchEngineException
Description copied from interface: ResultSet
Clusters the results into this set into a number of clusters. The algorithm used depends on how the engine that generated this set of results is configured.

Specified by:
cluster in interface ResultSet
Parameters:
field - the name of a vectored field upon which the clustering should be based. A value of null indicates that all vectored fields should be considered, while an empty string indicates that data in no explicit field should be considered.
k - the maximum number of clusters to return
Returns:
a set of clusters containing the results in this set. The number of clusters returned may be less than or equal to k
Throws:
SearchEngineException - if there are any errors generating the clusters
See Also:
ResultsCluster

groupBy

public java.util.Set<ResultsCluster> groupBy(java.lang.String field,
                                             boolean ignoreCase)
                                      throws SearchEngineException
Description copied from interface: ResultSet
Groups the results in this set into a number of clusters. The results are broken into groups based on the values in the given field. If a result has more than one value for this field, then it will appear in the group for each field.

Specified by:
groupBy in interface ResultSet
Parameters:
field - the name of the field for which we wish to group the results
ignoreCase - if true case will not be taken into account when grouping the results. Clearly, this only makes sense for string fields.
Returns:
a set of clusters grouped by the values of the given field
Throws:
SearchEngineException - if there are any errors grouping the results

weight

public ResultSet weight(float w)
Description copied from interface: ResultSet
Weights the results in this set.

Specified by:
weight in interface ResultSet
Parameters:
w - a weight to apply multiplicatively to each of the scores in this set.
Returns:
a new result set with the weights applied. If no normalization is requested, then the scores for results in the new set may be greater than 0.

intersect

public ResultSet intersect(ResultSet rs)
Description copied from interface: ResultSet
Computes the intersection of this result set with another result set.

Specified by:
intersect in interface ResultSet
Parameters:
rs - the result set with which this set will be intersected.
Returns:
a new result set containing only thos documents that occur in both this set and the set passed in. The score for documents in the returned set that occur in both sets will be the sum of the scores from the two sets. Note that this may result in scores greater than 1 for these documents!

union

public ResultSet union(ResultSet rs)
Description copied from interface: ResultSet
Computes the intersection of this result set with another result set.

Specified by:
union in interface ResultSet
Parameters:
rs - the result set with which this set will be intersected.
Returns:
a new result set containing the documents that occur in either this set or the set passed in (or both). The score for documents in the returned set that occur in both sets will be the sum of the scores from the two sets. Note that this may result in scores greater than 1 for these documents!

difference

public ResultSet difference(ResultSet rs)
Description copied from interface: ResultSet
Computes the difference of this result set and another result set.

Specified by:
difference in interface ResultSet
Parameters:
rs - the result set with which this set will be intersected.
Returns:
a new result set containing the documents that occur in this set, but not the set passed in.

same

public boolean same(ResultSetImpl other)
A method to test whether two result sets are the same.

Parameters:
other - the other set to test against this one.
Returns:
true if the documents contain the same documents and the documents have the same scores, false otherwise.