Package ome.api
Interface Search
-
- All Superinterfaces:
java.util.Iterator<ome.model.IObject>
,ServiceInterface
,StatefulServiceInterface
public interface Search extends StatefulServiceInterface, java.util.Iterator<ome.model.IObject>
Central search interface, allowing Web2.0 style queries. EachSearch
instance keeps up with several queries and lazily-loads the results ashasNext()
,next()
andresults()
are called. These queries are created by the "by*" methods. Each instance also has a number of settings which can all be changed from their defaults via accessors, e.g.setBatchSize(int)
orsetCaseSensitive(boolean)
. The only methods which are required for the proper functioning of aSearch
instance are:onlyType(Class)
,onlyTypes(Class...)
ORallTypes()
- Any by* method to create a query
allTypes()
method is discouraged, since it is possibly very resource intensive, which is why any attempt to receive results without specifically setting types or allowing all is prohibited.- Since:
- 3.0-Beta3
- See Also:
IQuery
-
-
Field Summary
Fields Modifier and Type Field Description static boolean
ALLOW_LEADING_WILDCARD
Defaultleading-wildcard setting
static java.lang.String
DATE_TYPE_ACQUISITION
Treat date range as acquisition datestatic java.lang.String
DATE_TYPE_IMPORT
Treat date range as import datestatic int
DEFAULT_BATCH_SIZE
Defaultbatch size
static boolean
DEFAULT_CASE_SENSITIVTY
Defaultcase sensitivity
static boolean
DEFAULT_MERGED_BATCHES
Defaultmerged-batches
static boolean
DEFAULT_RETURN_UNLOADED
Defaultreturn-unloaded
static boolean
DEFAULT_USE_PROJECTIONS
Defaultuse-projections
static java.lang.String
SCORE
String
constant used to look up the score value of Lucene queries returned by this interface.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description int
activeQueries()
Returns the number of active queries.void
addOrderByAsc(java.lang.String path)
A path from the target entity which will be added to the current stack of order statements applied to the query.void
addOrderByDesc(java.lang.String path)
A path from the target entity which will be added to the current stack of order statements applied to the query.void
allTypes()
Permits all types to be returned.void
and()
void
byAnnotatedWith(ome.model.annotations.Annotation... examples)
Finds entities annotated with anAnnotation
similar to the example.void
byFullText(java.lang.String query)
Passes the query as is to the Lucene backend.void
byGroupForTags(java.lang.String group)
Returns transient (without ID)TagAnnotation
instances which represent all thetags
in the given group.void
byHqlQuery(java.lang.String query, ome.parameters.Parameters p)
Delegates toIQuery.findAllByQuery(String, Parameters)
method to take advantage of theand()
,or()
, andnot()
methods, or queue-semantics.void
byLuceneQueryBuilder(java.lang.String fields, java.lang.String from, java.lang.String to, java.lang.String dateType, java.lang.String query)
Builds a Lucene query and passes it to the Lucene backend.void
bySimilarTerms(java.lang.String... terms)
Returns transient (without ID)TextAnnotation
instances which represent terms which are similar to the given terms.void
bySomeMustNone(java.lang.String[] some, java.lang.String[] must, java.lang.String[] none)
Builds a Lucene query and passes it tobyFullText(String)
.void
byTagForGroups(java.lang.String tag)
Creates a query which will return transient (without ID)TagAnnotation
instances which represent all thetag groups
which the given tag belongs to.void
clearQueries()
Removes all active queries (leavingsettings
alone), such thatactiveQueries()
will return 0.java.util.Map<java.lang.String,ome.model.annotations.Annotation>
currentMetadata()
Provides access to the extra query information (for example Lucene score and boost values) for a single call tonext()
.java.util.List<java.util.Map<java.lang.String,ome.model.annotations.Annotation>>
currentMetadataList()
Provides access to the extra query information (for example Lucene score and boost values) for a single call toresults()
.void
fetchAlso(java.lang.String... fetches)
Adds a fetch clause for loading non-annotation fields of returned entities.void
fetchAnnotations(java.lang.Class... classes)
Queries the database for allannotations
of the given types for all returned instances.int
getBatchSize()
Returns the current batch size.boolean
hasNext()
Returns true if another call tonext()
is valid.boolean
isAllowLeadingWildcard()
Returns the current leading-wildcard setting.boolean
isCaseSensitive()
Returns the current case sensitivity setting.boolean
isMergedBatches()
Returns the current merged-batches setting.boolean
isReturnUnloaded()
Returns the current return-unloaded setting.boolean
isUseProjections()
Returns the current use-projection setting.ome.model.IObject
next()
Returns the next entity from the current query.void
not()
void
notAnnotatedBy(ome.model.internal.Details d)
Restricts entities by who has not annotated them with anAnnotation
matching the other filters.void
notOwnedBy(ome.model.internal.Details d)
Uses theDetails.getOwner()
andDetails.getGroup()
information to restrict the entities which will be returned.void
onlyAnnotatedBetween(java.sql.Timestamp start, java.sql.Timestamp stop)
Restricts entities by the time in which any annotation (which matches the other filters) was added them.void
onlyAnnotatedBy(ome.model.internal.Details d)
Restricts entities by who has annotated them with anAnnotation
matching the other filters.void
onlyAnnotatedWith(java.lang.Class... classes)
Restricts entities to having anAnnotation
of all the given types.void
onlyCreatedBetween(java.sql.Timestamp start, java.sql.Timestamp stop)
Restricts the time between which an entity may have been created.void
onlyIds(java.lang.Long... ids)
Restricts the set ofids
which will be checked.void
onlyModifiedBetween(java.sql.Timestamp start, java.sql.Timestamp stop)
Restricts the time between which an entity may have last been modified.void
onlyOwnedBy(ome.model.internal.Details d)
Uses theDetails.getOwner()
andDetails.getGroup()
information to restrict the entities which will be returned.<T extends ome.model.IObject>
voidonlyType(java.lang.Class<T> klass)
Restricts the search to a single type.<T extends ome.model.IObject>
voidonlyTypes(java.lang.Class<T>... classes)
Restricts searches to a set of types.void
or()
void
remove()
Unsupported operation.void
resetDefaults()
Resets all settings (non-query state) to the original default values, as if the instance had just be created.<T extends ome.model.IObject>
java.util.List<T>results()
Returns up tobatch size
number of results along with the related query metadata.void
setAllowLeadingWildcard(boolean allowLeadingWildcard)
Permits full-text queries with a leading query if true.void
setBatchSize(int size)
Sets the maximum number of results that will be returned by one call toresults()
.void
setCaseSensitive(boolean caseSensitive)
Sets the case sensitivity on all queries where case-sensitivity is supported.void
setCaseSentivice(boolean caseSensitive)
Deprecated.void
setMergedBatches(boolean merge)
Set whether or not results from two separate queries can be returned in the same call toresults()
.void
setReturnUnloaded(boolean returnUnloaded)
Determines if all results should be returned as unloaded objects.void
setUseProjections(boolean useProjections)
Determines if Lucene queries should not hit the database.void
unordered()
Removes the current stack of order statements.-
Methods inherited from interface ome.api.StatefulServiceInterface
activate, close, getCurrentEventContext, passivate
-
-
-
-
Field Detail
-
SCORE
static final java.lang.String SCORE
String
constant used to look up the score value of Lucene queries returned by this interface. Not all queries will fill this value.- See Also:
- Constant Field Values
-
DEFAULT_BATCH_SIZE
static final int DEFAULT_BATCH_SIZE
Defaultbatch size
- See Also:
- Constant Field Values
-
DEFAULT_MERGED_BATCHES
static final boolean DEFAULT_MERGED_BATCHES
Defaultmerged-batches
- See Also:
- Constant Field Values
-
DEFAULT_CASE_SENSITIVTY
static final boolean DEFAULT_CASE_SENSITIVTY
Defaultcase sensitivity
- See Also:
- Constant Field Values
-
DEFAULT_USE_PROJECTIONS
static final boolean DEFAULT_USE_PROJECTIONS
Defaultuse-projections
- See Also:
- Constant Field Values
-
DEFAULT_RETURN_UNLOADED
static final boolean DEFAULT_RETURN_UNLOADED
Defaultreturn-unloaded
- See Also:
- Constant Field Values
-
ALLOW_LEADING_WILDCARD
static final boolean ALLOW_LEADING_WILDCARD
Defaultleading-wildcard setting
- See Also:
- Constant Field Values
-
DATE_TYPE_IMPORT
static final java.lang.String DATE_TYPE_IMPORT
Treat date range as import date- See Also:
- Constant Field Values
-
DATE_TYPE_ACQUISITION
static final java.lang.String DATE_TYPE_ACQUISITION
Treat date range as acquisition date- See Also:
- Constant Field Values
-
-
Method Detail
-
activeQueries
int activeQueries()
Returns the number of active queries. This means thatactiveQueries
gives the minimum number of remaining calls toresults()
when batches are notmerged
.- Returns:
- number of active queries
-
setBatchSize
void setBatchSize(int size)
Sets the maximum number of results that will be returned by one call toresults()
. If batches are notmerged
, then results may often be less than the batch size. If batches aremerged
, then only the last call toresults()
can be less than batch size. Note: some query types may not support batching at the query level, and all instances must then be loaded into memory simultaneously.- Parameters:
size
- maximum number of results per call toresults()
-
getBatchSize
int getBatchSize()
Returns the current batch size. IfsetBatchSize(int)
has not been called, thedefault value
will be in effect.- Returns:
- maximum number of results per call to
results()
- See Also:
DEFAULT_BATCH_SIZE
-
setMergedBatches
void setMergedBatches(boolean merge)
Set whether or not results from two separate queries can be returned in the same call toresults()
.
-
isMergedBatches
boolean isMergedBatches()
Returns the current merged-batches setting. IfsetMergedBatches(boolean)
has not been called, thedefault value
will be in effect.
-
setCaseSentivice
@Deprecated void setCaseSentivice(boolean caseSensitive)
Deprecated.Sets the case sensitivity on all queries where case-sensitivity is supported.
-
setCaseSensitive
void setCaseSensitive(boolean caseSensitive)
Sets the case sensitivity on all queries where case-sensitivity is supported.
-
isCaseSensitive
boolean isCaseSensitive()
Returns the current case sensitivity setting. IfsetCaseSentivice(boolean)
has not been called, thedefault value
will be in effect.
-
setUseProjections
void setUseProjections(boolean useProjections)
Determines if Lucene queries should not hit the database. Instead all values which are stored in the index will be loaded into the object, which includes the id. However, the entity will not be marked unloaded and therefore it is especially important to not allow a projection-instance to be saved back to the server. This can result in DATA LOSS.
-
isUseProjections
boolean isUseProjections()
Returns the current use-projection setting. If true, the client must be careful with all results that are returned. Seefor more.
IfsetUseProjections(boolean)
has not been called, theDEFAULT_USE_PROJECTIONS
will be in effect.
-
setReturnUnloaded
void setReturnUnloaded(boolean returnUnloaded)
Determines if all results should be returned as unloaded objects. This is particularly useful for creating lists for further querying viaIQuery
. This value overrides thesetUseProjections(boolean)
setting.
-
isReturnUnloaded
boolean isReturnUnloaded()
Returns the current return-unloaded setting. If true, all returned entities will be unloaded. IfsetReturnUnloaded(boolean)
has not been called, thedefault value
will be in effect.
-
setAllowLeadingWildcard
void setAllowLeadingWildcard(boolean allowLeadingWildcard)
Permits full-text queries with a leading query if true.
-
isAllowLeadingWildcard
boolean isAllowLeadingWildcard()
Returns the current leading-wildcard setting. If false,byFullText(String)
andbySomeMustNone(String[], String[], String[])
will throw anApiUsageException
, since leading-wildcard searches are quite slow. UsesetAllowLeadingWildcard(boolean)
in order to permit this usage.
-
onlyType
<T extends ome.model.IObject> void onlyType(java.lang.Class<T> klass)
Restricts the search to a single type. All return values will match this type.
-
onlyTypes
<T extends ome.model.IObject> void onlyTypes(java.lang.Class<T>... classes)
Restricts searches to a set of types. The entities returned are guaranteed to be one of these types.
-
allTypes
void allTypes()
Permits all types to be returned. For some types of queries, this carries a performance penalty as every database table must be hit.
-
onlyIds
void onlyIds(java.lang.Long... ids)
Restricts the set ofids
which will be checked. This is useful for testing one of the given restrictions on a reduced set of objects.- Parameters:
ids
- Can be null, in which case the previous restriction is removed.
-
onlyOwnedBy
void onlyOwnedBy(ome.model.internal.Details d)
Uses theDetails.getOwner()
andDetails.getGroup()
information to restrict the entities which will be returned. If both are non-null, the two restrictions are joined by an AND.- Parameters:
d
- Can be null, in which case the previous restriction is removed.
-
notOwnedBy
void notOwnedBy(ome.model.internal.Details d)
Uses theDetails.getOwner()
andDetails.getGroup()
information to restrict the entities which will be returned. If both are non-null, the two restrictions are joined by an AND.- Parameters:
d
- Can be null, in which case the previous restriction is removed.
-
onlyCreatedBetween
void onlyCreatedBetween(java.sql.Timestamp start, java.sql.Timestamp stop)
Restricts the time between which an entity may have been created.- Parameters:
start
- Can be null, i.e. interval open to negative infinity.stop
- Can be null, i.e. interval opens to positive infinity.
-
onlyModifiedBetween
void onlyModifiedBetween(java.sql.Timestamp start, java.sql.Timestamp stop)
Restricts the time between which an entity may have last been modified.- Parameters:
start
- Can be null, i.e. interval open to negative infinity.stop
- Can be null, i.e. interval open to positive infinity.
-
onlyAnnotatedBetween
void onlyAnnotatedBetween(java.sql.Timestamp start, java.sql.Timestamp stop)
Restricts entities by the time in which any annotation (which matches the other filters) was added them. This matches thecreation event
of theAnnotation
.- Parameters:
start
- Can be null, i.e. interval open to negative infinity.stop
- Can be null, i.e. interval open to positive infinity.
-
onlyAnnotatedBy
void onlyAnnotatedBy(ome.model.internal.Details d)
Restricts entities by who has annotated them with anAnnotation
matching the other filters. AsonlyOwnedBy(Details)
, theDetails.getOwner()
andDetails.getGroup()
information is combined with an AND condition.- Parameters:
d
- Can be null, in which case any previous restriction is removed.
-
notAnnotatedBy
void notAnnotatedBy(ome.model.internal.Details d)
Restricts entities by who has not annotated them with anAnnotation
matching the other filters. AsnotOwnedBy(Details)
, theDetails.getOwner()
andDetails.getGroup()
information is combined with an AND condition.- Parameters:
d
- Can be null, in which case any previous restriction is removed.
-
onlyAnnotatedWith
void onlyAnnotatedWith(java.lang.Class... classes)
Restricts entities to having anAnnotation
of all the given types. This is useful in combination with the other onlyAnnotated* methods to say, e.g., only annotated with a file by user X. By default, this value isnull
and imposes no restriction. Passing an empty array implies an object that is not annotated at all. Note: If the semantics were OR, then a client would have to query each class individually, and compare all the various values, checking which ids are where. However, since this method defaults to AND, multiple calls (optionally withisMergedBatches()
andisReturnUnloaded()
) and combine the results. Duplicate ids are still possible, so a set of some form should be used to collect the results.- Parameters:
classes
- Can be empty, in which case restriction is removed.
-
addOrderByAsc
void addOrderByAsc(java.lang.String path)
A path from the target entity which will be added to the current stack of order statements applied to the query.- Parameters:
path
- Non-null.- See Also:
unordered()
-
addOrderByDesc
void addOrderByDesc(java.lang.String path)
A path from the target entity which will be added to the current stack of order statements applied to the query.- Parameters:
path
- Non-null.- See Also:
unordered()
-
unordered
void unordered()
Removes the current stack of order statements.- See Also:
addOrderByAsc(String)
,addOrderByDesc(String)
-
fetchAnnotations
void fetchAnnotations(java.lang.Class... classes)
Queries the database for allannotations
of the given types for all returned instances.- Parameters:
classes
- Can be empty, which removes previous fetch setting.
-
fetchAlso
void fetchAlso(java.lang.String... fetches)
Adds a fetch clause for loading non-annotation fields of returned entities. Each fetch is a hibernate clause in dot notation.- Parameters:
fetches
- Can be empty, which removes previous fetch setting.
-
resetDefaults
void resetDefaults()
Resets all settings (non-query state) to the original default values, as if the instance had just be created.
-
bySimilarTerms
void bySimilarTerms(java.lang.String... terms)
Returns transient (without ID)TextAnnotation
instances which represent terms which are similar to the given terms. For example, if the argument is "cell", one return value might have as its textValue: "cellular" while another has "cellularize". No filtering or fetching is performed.- Parameters:
terms
- Cannot be empty.
-
byGroupForTags
void byGroupForTags(java.lang.String group)
Returns transient (without ID)TagAnnotation
instances which represent all thetags
in the given group. The entities are transient and without ownership since multiple users can own the same tag. This method will override settings for types.- Parameters:
group
- Can be null or empty to return all tags.
-
byTagForGroups
void byTagForGroups(java.lang.String tag)
Creates a query which will return transient (without ID)TagAnnotation
instances which represent all thetag groups
which the given tag belongs to. The entities are transient and without ownership since multiple users can own the same tag group. This method will override settings for types.- Parameters:
tag
- Can be null or empty to return all groups.
-
byFullText
void byFullText(java.lang.String query)
Passes the query as is to the Lucene backend.- Parameters:
query
- May not be null or of zero length.
-
byLuceneQueryBuilder
void byLuceneQueryBuilder(java.lang.String fields, java.lang.String from, java.lang.String to, java.lang.String dateType, java.lang.String query)
Builds a Lucene query and passes it to the Lucene backend.- Parameters:
fields
- The fields (comma separated) to search in (name, description, ...)from
- The date range from, in the form YYYYMMDD (may be null)to
- The date range to (inclusive), in the form YYYYMMDD (may be null)dateType
-DATE_TYPE_ACQUISITION
orDATE_TYPE_IMPORT
query
- May not be null or of zero length.
-
bySomeMustNone
void bySomeMustNone(java.lang.String[] some, java.lang.String[] must, java.lang.String[] none)
Builds a Lucene query and passes it tobyFullText(String)
.- Parameters:
some
- Some (at least one) of these terms must be present in the document. May be null.must
- All of these terms must be present in the document. May be null.none
- None of these terms may be present in the document. May be null.
-
byHqlQuery
void byHqlQuery(java.lang.String query, ome.parameters.Parameters p)
Delegates toIQuery.findAllByQuery(String, Parameters)
method to take advantage of theand()
,or()
, andnot()
methods, or queue-semantics.- Parameters:
query
- Not null.p
- May be null. Defaults are then in effect.- See Also:
IQuery.findAllByQuery(String, Parameters)
-
byAnnotatedWith
void byAnnotatedWith(ome.model.annotations.Annotation... examples)
Finds entities annotated with anAnnotation
similar to the example. This does not use Hibernate'sQuery-By-Example
mechanism, since that cannot handle joins. The fields which are used are:- the main content of the annotation : String,
OriginalFile.getId()
, etc.
If the main content is null it is assumed to be a wildcard searched, and only the type of the annotation is searched. Currently, ListAnnotations are not supported.
- Parameters:
examples
- Not empty.
- the main content of the annotation : String,
-
or
void or()
Applies the next by* method to the previous by* method, so that a callhasNext()
,next()
, orresults()
sees only the union of the two calls. For example,service.onlyType(Image.class); service.byFullText("foo"); service.or(); service.onlyType(Dataset.class); service.byFullText("foo");
will return both Images and Datasets together. Calling this method overrides a previous setting ofand()
ornot()
. If there is no active queries (i.e.activeQueries()
greater than 0), then anApiUsageException
will be thrown.
-
and
void and()
Applies the next by* method to the previous by* method, so that a callhasNext()
,next()
, orresults()
sees only the intersection of the two calls. For example,service.onlyType(Image.class); service.byFullText("foo"); service.intersection(); service.byAnnotatedWith(TagAnnotation.class);
will return only the Images with TagAnnotations.Calling this method overrides a previous setting of
or()
ornot()
. If there is no active queries (i.e.activeQueries()
greater than 0), then anApiUsageException
will be thrown.
-
not
void not()
Applies the next by* method to the previous by* method, so that a callhasNext()
,next()
, orresults()
sees only the intersection of the two calls. For example,service.onlyType(Image.class); service.byFullText("foo"); service.complement(); service.byAnnotatedWith(TagAnnotation.class);
will return all the Images not annotated with TagAnnotation.Calling this method overrides a previous setting of
or()
orand()
. If there is no active queries (i.e.activeQueries()
greater than 0), then anApiUsageException
will be thrown.
-
clearQueries
void clearQueries()
Removes all active queries (leavingsettings
alone), such thatactiveQueries()
will return 0.
-
hasNext
boolean hasNext()
Returns true if another call tonext()
is valid. A call tonext()
may throw an exception for another reason, however.- Specified by:
hasNext
in interfacejava.util.Iterator<ome.model.IObject>
-
next
ome.model.IObject next() throws ome.conditions.ApiUsageException
Returns the next entity from the current query. If the previous call returned the last entity from a given query, the first entity from the next query will be returned andactiveQueries()
decremented. Since this method only returns the entity itself, a single call tocurrentMetadata()
may follow this call to gather the extra metadata which is returned in the map viaresults()
.- Specified by:
next
in interfacejava.util.Iterator<ome.model.IObject>
- Throws:
ome.conditions.ApiUsageException
- ifhasNext()
returns false.
-
currentMetadata
java.util.Map<java.lang.String,ome.model.annotations.Annotation> currentMetadata()
-
remove
void remove() throws java.lang.UnsupportedOperationException
Unsupported operation.- Specified by:
remove
in interfacejava.util.Iterator<ome.model.IObject>
- Throws:
java.lang.UnsupportedOperationException
-
results
<T extends ome.model.IObject> java.util.List<T> results() throws ome.conditions.ApiUsageException
Returns up tobatch size
number of results along with the related query metadata. Ifbatches are merged
then the results from multiple queries may be returned together.- Throws:
ome.conditions.ApiUsageException
- ifhasNext()
returns false.
-
currentMetadataList
java.util.List<java.util.Map<java.lang.String,ome.model.annotations.Annotation>> currentMetadataList()
-
-