Package com.jalios.jcms
Class QueryResultSet
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<Publication>,Collection<Publication>,Set<Publication>
This class holds results of a query.
It keeps tracks of all results (
It keeps tracks of all results (
Publication) from a query and their scores.- Since:
- jcms-5.5.0
- Author:
- Olivier Jaquemet
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classQueryResultSet.ScoreComparator<T extends Publication>ThisComparatorcompares twoObjects using a score retrieved from a map ofObjecttofloat. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(Publication pub, float score) Adds the givenPublicationand its score to thisQueryResultSet.booleanaddAll(PageResult<Publication> pr) Adds the givenPageResultto thisQueryResultSet.booleanaddAll(QueryResultSet resultSet) Adds all thePublicationin the specified result Set to thisQueryResultSet.booleanaddAll(Collection<? extends Publication> coll) OverridesAbstractCollection.addAll(Collection)to call whenaddAll(QueryResultSet)if the specified collection is aQueryResultSet.booleanaddAll(Collection<? extends Publication> coll, float score) Adds all thePublicationin the specified collection to thisQueryResultSet.voidclear()Clear all Object from this result set (also remove associated score).Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) using theScoreComparator.getAsSortedSet(Class<? extends Publication> typeClazz, String comparatorName, boolean reverse) Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) retrieving the appropriateComparatorthroughComparatorManager.getAsSortedSet(String comparatorName, boolean reverse) Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) retrieving the appropriateComparatorthroughComparatorManager.getAsSortedSet(Comparator comparator) Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) using the givenComparatoror none if null.getAttribute(String name) Returns the value of the named attribute as anObject, ornullif no attribute of the given name exists.Returns a java.util.Map of the attributes of this results.floatRetrieve the maximum score value available in thisQueryResultSet.floatRetrieve the minimum score value available in thisQueryResultSet.intfloatgetScore(Publication pub) Retrieve score of the specifiedPublication.floatDeprecated.static ComparatorgetScoreComparator(QueryResultSet resultSet, Comparator parentComparator) Gets a new instance of aScoreComparatorfor relevance sorting of the givenQueryResultSet.intCAUTION: This is an internal method.booleanisHybrid()booleaniterator()OverridesHashSet.iterator()to wrap the nativeIteratorinstance returned by the Java API with a custom one making sure the max score is updated on removal.booleanRemove the given Object from this result set (also remove associated score).removeAttribute(String name) Removes an attribute from this result.booleanretainAll(QueryResultSet resultSet) Retains only the elements in thisQueryResultSetthat are contained in the specifiedQueryResultSet.booleanretainAll(Collection<?> coll) OverridesAbstractCollection.retainAll(Collection)to call whenretainAll(QueryResultSet)if the specified collection is aQueryResultSet.setAttribute(String name, Object obj) Stores an attribute in this result.voidsetHybrid(boolean isHybrid) voidsetStatus(PageResult.Status status) voidsetTotalAccurate(boolean isTotalAccurate) Indicates if the total size accuratevoidsetTotalSize(int totalSize) Assigns the total size of thisQueryResultSet.Methods inherited from class java.util.HashSet
add, clone, contains, isEmpty, newHashSet, size, spliterator, toArray, toArrayMethods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
containsAll, equals, hashCode, removeAll
-
Constructor Details
-
QueryResultSet
public QueryResultSet()
-
-
Method Details
-
setAttribute
Stores an attribute in this result.
If the object passed in is null, the effect is the same as callingremoveAttribute(java.lang.String).- Parameters:
name- aStringspecifying the name of the attributeobj- theObjectto be stored- Returns:
- previous value associated with specified name, or
nullif there was no mapping for name. Anullreturn can also indicate thatnullwas associated with the specified name.
-
removeAttribute
Removes an attribute from this result.- Parameters:
name- aStringspecifying- Returns:
- previous value associated with specified name, or
nullif there was no mapping for name. Anullreturn can also indicate thatnullwas associated with the specified name.
-
getAttribute
Returns the value of the named attribute as anObject, ornullif no attribute of the given name exists.- Parameters:
name- aStringspecifying the name of the attribute- Returns:
- an
Objectcontaining the value of the attribute, ornullif the attribute does not exist
-
getAttributeMap
Returns a java.util.Map of the attributes of this results.- Returns:
- the internal Map used by this results, modify with care.
-
add
Adds the givenPublicationand its score to thisQueryResultSet.
If a score for the givenObjectwas already in thisQueryResultSetfor a given element, its score is replaced.- Parameters:
pub- thePublicationto add.score- the new score of thePublication- Returns:
trueif the set did not already contain the specified element.- Since:
- jcms-5.5.0
-
addAll
Adds all thePublicationin the specified collection to thisQueryResultSet.
If a score was already in theCollectionfor a given element, its score is replaced.- Parameters:
coll- collection whose elements are to be added to this collection.score- the score of thePublicationin theCollection(should be between 0.0f and 1.0f)- Returns:
trueif this collection changed as a result of the call.- Since:
- jcms-5.5.0
-
addAll
Adds all thePublicationin the specified result Set to thisQueryResultSet. Also puts all attribute of the specified QueryResultSet into this QueryResultSet.
If aPublicationwas already in thisQueryResultSet, it is replaced with its score in the givenQueryResultSet.- Parameters:
resultSet-QueryResultSetwhose elements are to be added to this QueryResultSet.- Returns:
trueif this collection changed as a result of the call.- Since:
- jcms-5.5.0
-
retainAll
Retains only the elements in thisQueryResultSetthat are contained in the specifiedQueryResultSet. In other words, removes from thisQueryResultSetall of its elements that are not contained in the specifiedQueryResultSet.Also updates scores of elements kept in this
QueryResultSetif their existing score are below the score of the specifiedQueryResultSet.- Parameters:
resultSet- elements to be retained in this collection.- Returns:
trueif thisQueryResultSetchanged as a result of the call.- Since:
- jcms-5.7.0
-
iterator
OverridesHashSet.iterator()to wrap the nativeIteratorinstance returned by the Java API with a custom one making sure the max score is updated on removal.Needed for bug fix JCMS-3368.
- Specified by:
iteratorin interfaceCollection<Publication>- Specified by:
iteratorin interfaceIterable<Publication>- Specified by:
iteratorin interfaceSet<Publication>- Overrides:
iteratorin classHashSet<Publication>- Since:
- jcms-5.7.0
- See Also:
-
addAll
OverridesAbstractCollection.addAll(Collection)to call whenaddAll(QueryResultSet)if the specified collection is aQueryResultSet.- Specified by:
addAllin interfaceCollection<Publication>- Specified by:
addAllin interfaceSet<Publication>- Overrides:
addAllin classAbstractCollection<Publication>- Since:
- jcms-5.7.0
- See Also:
-
retainAll
OverridesAbstractCollection.retainAll(Collection)to call whenretainAll(QueryResultSet)if the specified collection is aQueryResultSet.- Specified by:
retainAllin interfaceCollection<Publication>- Specified by:
retainAllin interfaceSet<Publication>- Overrides:
retainAllin classAbstractCollection<Publication>- Since:
- jcms-5.7.0
- See Also:
-
addAll
Adds the givenPageResultto thisQueryResultSet.- Parameters:
pr- thePageResult- Returns:
trueif thisQueryResultSetchanged as a result of the call.- Since:
- jcms-7.0.1
-
remove
Remove the given Object from this result set (also remove associated score).- Specified by:
removein interfaceCollection<Publication>- Specified by:
removein interfaceSet<Publication>- Overrides:
removein classHashSet<Publication>- Since:
- jcms-5.5.0
- See Also:
-
clear
public void clear()Clear all Object from this result set (also remove associated score).- Specified by:
clearin interfaceCollection<Publication>- Specified by:
clearin interfaceSet<Publication>- Overrides:
clearin classHashSet<Publication>- Since:
- jcms-5.5.0
- See Also:
-
getScore
Deprecated.Retrieve score of the givenObject(aPublication).- Parameters:
obj- theObject(aPublication) from which to retrieve the score.- Returns:
- score associated with given
objor 0.0f if no score is available for thisObject. - Since:
- jcms-5.5.0
-
getScore
Retrieve score of the specifiedPublication.- Parameters:
pub- thePublicationfrom which to retrieve the score.- Returns:
- score associated with given
objor 0.0f if no score is available for thisPublication. - Since:
- jcms-6.0.0
-
getMaxScore
public float getMaxScore()Retrieve the maximum score value available in thisQueryResultSet.- Returns:
- a float with the maximum score value.
-
getMinScore
public float getMinScore()Retrieve the minimum score value available in thisQueryResultSet.- Returns:
- a float with the minimum score value.
-
getAsSortedSet
Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) using theScoreComparator. Because this method sort all the result in a newTreeSet, this method is expensive, be careful when using it.- Returns:
- a new
SortedSet(aTreeSet) usingScoreComparator. - Since:
- jcms-5.5.0
- See Also:
-
getAsSortedSet
Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) using the givenComparatoror none if null.Because this method sort all the result in a new
TreeSet, this method is expensive, be careful when using it.- Parameters:
comparator- theComparatorto use in theSortedSet, can be null to sort using natural order.- Returns:
- a new
SortedSet(aTreeSet) usingScoreComparator. - Since:
- jcms-5.5.0
- See Also:
-
getAsSortedSet
Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) retrieving the appropriateComparatorthroughComparatorManager.Because this method sort all the result in a new
TreeSet, this method is expensive, be careful when using it.- Parameters:
comparatorName- the name of theComparatorto use in theSortedSet, as available throughComparatorManager.reverse- a boolean indicating whether the comparator should have its behavior reversed (true) or unchanged (false)- Returns:
- a new
SortedSet - Since:
- jcms-7.1.0
-
getAsSortedSet
public SortedSet<Publication> getAsSortedSet(Class<? extends Publication> typeClazz, String comparatorName, boolean reverse) Gets all the results contained in thisQueryResultSetas aSortedSet(aTreeSet) retrieving the appropriateComparatorthroughComparatorManager.Because this method sort all the result in a new
TreeSet, this method is expensive, be careful when using it.- Parameters:
typeClazz- the Class of Publication to sortcomparatorName- the name of theComparatorto use in theSortedSet, as available throughComparatorManager.reverse- a boolean indicating whether the comparator should have its behavior reversed (true) or unchanged (false)- Returns:
- a new
SortedSet - Since:
- jcms-7.1.0
-
getScoreComparator
Gets a new instance of aScoreComparatorfor relevance sorting of the givenQueryResultSet.- Parameters:
resultSet- theQueryResultSetfrom which to retrieve score of eachPublication.parentComparator- theComparatorto use when score of comparedObjectare identical.- Returns:
- parentComparator is resultSet is null, new instance of
ScoreComparatorusing the given parent Comparator. - See Also:
-
getTotalSize
public int getTotalSize()CAUTION: This is an internal method. You SHOULD NOT use this method but rathergetResultSize(). Returns the total size of thisQueryResultSet(it may be much larger than getResultSize().size() with DB query).- Returns:
- the total size of this
QueryResultSet. - Since:
- jcms-7.0.1
-
setTotalSize
public void setTotalSize(int totalSize) Assigns the total size of thisQueryResultSet.- Parameters:
totalSize- the new total size.- Since:
- jcms-7.0.1
-
getResultSize
public int getResultSize() -
isHybrid
public boolean isHybrid() -
setHybrid
public void setHybrid(boolean isHybrid) -
setStatus
-
getStatus
-
isTotalAccurate
public boolean isTotalAccurate()- Returns:
- true if the total size is accurate.
- Since:
- jcms-9.0.2
-
setTotalAccurate
public void setTotalAccurate(boolean isTotalAccurate) Indicates if the total size accurate- Parameters:
isTotalAccurate- the value- Since:
- jcms-9.0.2
-
getScore(Publication)