@Transactional(readOnly=true) public class SearchBean extends AbstractStatefulBean implements Search
Search
interface.iQuery, iUpdate, modified, sec
ALLOW_LEADING_WILDCARD, DATE_TYPE_ACQUISITION, DATE_TYPE_IMPORT, DEFAULT_BATCH_SIZE, DEFAULT_CASE_SENSITIVTY, DEFAULT_MERGED_BATCHES, DEFAULT_RETURN_UNLOADED, DEFAULT_USE_PROJECTIONS, SCORE
Constructor and Description |
---|
SearchBean()
Empty constructor required by EJB and
self configuration . |
SearchBean(Executor executor,
Class<? extends org.apache.lucene.analysis.Analyzer> analyzer) |
Modifier and Type | Method and Description |
---|---|
void |
activate()
Completely restore this service for active use from whatever
passivation it has implemented.
|
int |
activeQueries()
Returns the number of active queries.
|
void |
addAction(SearchAction action) |
void |
addOrderByAsc(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(String path)
A path from the target entity which will be added to the current stack of
order statements applied to the query.
|
void |
addParameters(Parameters params) |
void |
addResult(List<IObject> result) |
void |
allTypes()
Permits all types to be returned.
|
void |
and()
Applies the next by* method to the previous by* method, so that a call
Search.hasNext() , Search.next() , or Search.results() sees only
the intersection of the two calls. |
void |
byAnnotatedWith(Annotation... examples)
Finds entities annotated with an
Annotation similar to the
example. |
void |
byFullText(String query)
Passes the query as is to the Lucene backend.
|
void |
byGroupForTags(String group)
Returns transient (without ID)
TagAnnotation instances which
represent all the tags in
the given group. |
void |
byHqlQuery(String query,
Parameters p)
Delegates to
IQuery.findAllByQuery(String, Parameters) method to
take advantage of the Search.and() , Search.or() , and
Search.not() methods, or queue-semantics. |
void |
byLuceneQueryBuilder(String fields,
String from,
String to,
String dateType,
String query)
Builds a Lucene query and passes it to the Lucene backend.
|
void |
bySimilarTerms(String... terms)
Returns transient (without ID)
TextAnnotation instances which represent
terms which are similar to the given terms. |
void |
bySomeMustNone(String[] some,
String[] must,
String[] none)
Builds a Lucene query and passes it to
Search.byFullText(String) . |
void |
byTagForGroups(String tag)
Creates a query which will return transient (without ID)
TagAnnotation instances which represent
all the tag groups which
the given tag belongs to. |
void |
byUUID(String[] uuids) |
void |
clearQueries()
Removes all active queries (leaving
settings
alone), such that Search.activeQueries() will return 0. |
void |
close()
signals the end of the service lifecycle.
|
Map<String,Annotation> |
currentMetadata()
Provides access to the extra query information (for example Lucene score
and boost values) for a single call to
Search.next() . |
List<Map<String,Annotation>> |
currentMetadataList()
Provides access to the extra query information (for example Lucene score
and boost values) for a single call to
Search.results() . |
<T extends IObject> |
fetchAlso(Map<T,String> fetches) |
void |
fetchAlso(String... fetches)
Adds a fetch clause for loading non-annotation fields of returned
entities.
|
void |
fetchAnnotations(Class... classes)
Queries the database for all
annotations of the given
types for all returned instances. |
int |
getBatchSize()
Returns the current batch size.
|
Class<? extends ServiceInterface> |
getServiceInterface() |
boolean |
hasNext()
Returns true if another call to
Search.next() 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.
|
void |
lastresultsAsWorkingGroup() |
IObject |
next()
Returns the next entity from the current query.
|
void |
not()
Applies the next by* method to the previous by* method, so that a call
Search.hasNext() , Search.next() , or Search.results() sees only
the intersection of the two calls. |
void |
notAnnotatedBy(Details d)
Restricts entities by who has not annotated them with an
Annotation matching the other filters. |
void |
notOwnedBy(Details d)
Uses the
Details.getOwner() and Details.getGroup()
information to restrict the entities which will be returned. |
void |
onlyAnnotatedBetween(Timestamp start,
Timestamp stop)
Restricts entities by the time in which any annotation (which matches the
other filters) was added them.
|
void |
onlyAnnotatedBy(Details d)
Restricts entities by who has annotated them with an
Annotation
matching the other filters. |
void |
onlyAnnotatedWith(Class... classes)
Restricts entities to having an
Annotation of all the given
types. |
void |
onlyCreatedBetween(Timestamp start,
Timestamp stop)
Restricts the time between which an entity may have been created.
|
void |
onlyIds(Long... ids)
Restricts the set of
ids which will be checked. |
void |
onlyModifiedBetween(Timestamp start,
Timestamp stop)
Restricts the time between which an entity may have last been modified.
|
void |
onlyOwnedBy(Details d)
Uses the
Details.getOwner() and Details.getGroup()
information to restrict the entities which will be returned. |
<T extends IObject> |
onlyType(Class<T> klass)
Restricts the search to a single type.
|
<T extends IObject> |
onlyTypes(Class<T>... classes)
Restricts searches to a set of types.
|
void |
or()
Applies the next by* method to the previous by* method, so that a call
Search.hasNext() , Search.next() , or Search.results() sees only
the union of the two calls. |
void |
passivate()
Perform whatever passivation is possible or throw an exception.
|
protected IObject |
pop(List<IObject> current)
Wrapper method which should be called on all results for the user.
|
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 IObject> |
results()
Returns up to
batch 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 |
setAnalyzer(Class<? extends org.apache.lucene.analysis.Analyzer> analyzer)
Injector used by Spring.
|
void |
setBatchSize(int size)
Sets the maximum number of results that will be returned by one call to
Search.results() . |
void |
setCaseSentivice(boolean caseSensitive)
Sets the case sensitivity on all queries where case-sensitivity is
supported.
|
void |
setExecutor(Executor executor)
Injector used by Spring, currently, since
SelfConfigurableService.selfConfigure() requires it. |
void |
setIdOnly() |
void |
setMaxClauseCount(Integer maxClauseCount)
Injector used by Spring.
|
void |
setMergedBatches(boolean merge)
Set whether or not results from two separate queries can be returned in
the same call to
Search.results() . |
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.
|
getBeanHelper, getCurrentEventContext, isModified, modified, selfConfigure, setQueryService, setSecuritySystem, setUpdateService
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCurrentEventContext
forEachRemaining
public SearchBean(Executor executor, Class<? extends org.apache.lucene.analysis.Analyzer> analyzer)
public SearchBean()
self configuration
.public Class<? extends ServiceInterface> getServiceInterface()
getServiceInterface
in interface SelfConfigurableService
public void setExecutor(Executor executor)
SelfConfigurableService.selfConfigure()
requires it.public void setAnalyzer(Class<? extends org.apache.lucene.analysis.Analyzer> analyzer)
public void setMaxClauseCount(Integer maxClauseCount)
@Transactional(readOnly=true) public void passivate()
StatefulServiceInterface
passivate
in interface StatefulServiceInterface
@Transactional(readOnly=true) public void activate()
StatefulServiceInterface
activate
in interface StatefulServiceInterface
@Transactional(readOnly=true) public void close()
StatefulServiceInterface
close
in interface StatefulServiceInterface
@Transactional public void byAnnotatedWith(Annotation... examples)
Search
Annotation
similar to the
example. This does not use Hibernate's
Query-By-Example
mechanism, since
that cannot handle joins. The fields which are used are:
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.
byAnnotatedWith
in interface Search
examples
- Not empty.@Transactional public void byFullText(String query)
Search
byFullText
in interface Search
query
- May not be null or of zero length.@Transactional public void byLuceneQueryBuilder(String fields, String from, String to, String dateType, String query)
Search
byLuceneQueryBuilder
in interface Search
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
- Search.DATE_TYPE_ACQUISITION
or Search.DATE_TYPE_IMPORT
query
- May not be null or of zero length.@Transactional public void byHqlQuery(String query, Parameters p)
Search
IQuery.findAllByQuery(String, Parameters)
method to
take advantage of the Search.and()
, Search.or()
, and
Search.not()
methods, or queue-semantics.byHqlQuery
in interface Search
query
- Not null.p
- May be null. Defaults are then in effect.IQuery.findAllByQuery(String, Parameters)
@Transactional public void bySomeMustNone(String[] some, String[] must, String[] none)
Search
Search.byFullText(String)
.bySomeMustNone
in interface Search
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.@Transactional public void bySimilarTerms(String... terms)
Search
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.bySimilarTerms
in interface Search
terms
- Cannot be empty.@Transactional public void byGroupForTags(String group)
Search
TagAnnotation
instances which
represent all the tags
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.byGroupForTags
in interface Search
group
- Can be null or empty to return all tags.@Transactional public void byTagForGroups(String tag)
Search
TagAnnotation
instances which represent
all the tag 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.byTagForGroups
in interface Search
tag
- Can be null or empty to return all groups.@Transactional public void byUUID(String[] uuids)
@Transactional public void or()
Search
Search.hasNext()
, Search.next()
, or Search.results()
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 of
Search.and()
or
Search.not()
. If there is no active queries (i.e.
Search.activeQueries()
> 0), then an ApiUsageException
will be
thrown.@Transactional public void and()
Search
Search.hasNext()
, Search.next()
, or Search.results()
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 Search.or()
or
Search.not()
. If there is no active queries (i.e.
Search.activeQueries()
> 0), then an ApiUsageException
will be
thrown.
@Transactional public void not()
Search
Search.hasNext()
, Search.next()
, or Search.results()
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 Search.or()
or
Search.and()
. If there is no active queries (i.e.
Search.activeQueries()
> 0), then an ApiUsageException
will be
thrown.
@Transactional public boolean hasNext()
Search
Search.next()
is valid. A call to
Search.next()
may throw an exception for another reason, however.@Transactional public IObject next() throws ApiUsageException
Search
Search.activeQueries()
decremented.
Since this method only returns the entity itself, a single call to
Search.currentMetadata()
may follow this call to gather the extra
metadata which is returned in the map via Search.results()
.next
in interface Iterator<IObject>
next
in interface Search
ApiUsageException
- if Search.hasNext()
returns false.@Transactional public Map<String,Annotation> currentMetadata()
Search
Search.next()
. This method may
only be called once for any given call to Search.next()
.currentMetadata
in interface Search
@Transactional public List<Map<String,Annotation>> currentMetadataList()
Search
Search.results()
. This method
may only be called once for any given call to Search.results()
.currentMetadataList
in interface Search
@Transactional public <T extends IObject> List<T> results()
Search
batch size
number of results along
with the related query metadata. If
batches are merged
then the results from
multiple queries may be returned together.protected IObject pop(List<IObject> current)
values
.@Transactional public void lastresultsAsWorkingGroup()
@Transactional public void remove() throws UnsupportedOperationException
Search
@Transactional public int activeQueries()
Search
activeQueries
gives the minimum number of remaining calls
to Search.results()
when batches are not
merged
.activeQueries
in interface Search
@Transactional public void clearQueries()
Search
settings
alone), such that Search.activeQueries()
will return 0.clearQueries
in interface Search
@Transactional public void resetDefaults()
Search
resetDefaults
in interface Search
@Transactional public void addOrderByAsc(String path)
Search
addOrderByAsc
in interface Search
path
- Non-null.Search.unordered()
@Transactional public void addOrderByDesc(String path)
Search
addOrderByDesc
in interface Search
path
- Non-null.Search.unordered()
@Transactional public void unordered()
Search
unordered
in interface Search
Search.addOrderByAsc(String)
,
Search.addOrderByDesc(String)
@Transactional public <T extends IObject> void fetchAlso(Map<T,String> fetches)
@Transactional public void fetchAnnotations(Class... classes)
Search
annotations
of the given
types for all returned instances.fetchAnnotations
in interface Search
classes
- Can be empty, which removes previous fetch setting.@Transactional public int getBatchSize()
Search
Search.setBatchSize(int)
has not
been called, the default value
will be in
effect.getBatchSize
in interface Search
Search.results()
Search.DEFAULT_BATCH_SIZE
@Transactional public boolean isCaseSensitive()
Search
Search.setCaseSentivice(boolean)
has not been called, the
default value
will be in effect.isCaseSensitive
in interface Search
@Transactional public boolean isMergedBatches()
Search
Search.setMergedBatches(boolean)
has not been called, the
default value
will be in effect.isMergedBatches
in interface Search
@Transactional public void onlyAnnotatedBetween(Timestamp start, Timestamp stop)
Search
creation event
of the
Annotation
.onlyAnnotatedBetween
in interface Search
start
- Can be null, i.e. interval open to negative infinity.stop
- Can be null, i.e. interval open to positive infinity.@Transactional public void onlyAnnotatedBy(Details d)
Search
Annotation
matching the other filters. As Search.onlyOwnedBy(Details)
, the
Details.getOwner()
and Details.getGroup()
information is
combined with an AND condition.onlyAnnotatedBy
in interface Search
d
- Can be null, in which case any previous restriction is
removed.@Transactional public void notAnnotatedBy(Details d)
Search
Annotation
matching the other filters. As
Search.notOwnedBy(Details)
, the Details.getOwner()
and
Details.getGroup()
information is combined with an AND condition.notAnnotatedBy
in interface Search
d
- Can be null, in which case any previous restriction is
removed.@Transactional public void onlyAnnotatedWith(Class... classes)
Search
Annotation
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 is null
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 with Search.isMergedBatches()
and
Search.isReturnUnloaded()
) and combine the results. Duplicate ids are
still possible, so a set of some form should be used to collect the
results.onlyAnnotatedWith
in interface Search
classes
- Can be empty, in which case restriction is removed.@Transactional public void onlyCreatedBetween(Timestamp start, Timestamp stop)
Search
onlyCreatedBetween
in interface Search
start
- Can be null, i.e. interval open to negative infinity.stop
- Can be null, i.e. interval opens to positive infinity.@Transactional public void onlyOwnedBy(Details d)
Search
Details.getOwner()
and Details.getGroup()
information to restrict the entities which will be returned. If both are
non-null, the two restrictions are joined by an AND.onlyOwnedBy
in interface Search
d
- Can be null, in which case the previous restriction is
removed.@Transactional public void onlyIds(Long... ids)
Search
ids
which will be checked.
This is useful for testing one of the given restrictions on a reduced set
of objects.@Transactional public void notOwnedBy(Details d)
Search
Details.getOwner()
and Details.getGroup()
information to restrict the entities which will be returned. If both are
non-null, the two restrictions are joined by an AND.notOwnedBy
in interface Search
d
- Can be null, in which case the previous restriction is
removed.@Transactional public void allTypes()
Search
@Transactional public <T extends IObject> void onlyType(Class<T> klass)
Search
@Transactional public <T extends IObject> void onlyTypes(Class<T>... classes)
Search
@Transactional public void setAllowLeadingWildcard(boolean allowLeadingWildcard)
Search
setAllowLeadingWildcard
in interface Search
Search.isAllowLeadingWildcard()
,
Search.byFullText(String)
,
Search.bySomeMustNone(String[], String[], String[])
@Transactional public void setBatchSize(int size)
Search
Search.results()
. If batches are not merged
,
then results may often be less than the batch size. If batches are
merged
, then only the last call to
Search.results()
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.setBatchSize
in interface Search
size
- maximum number of results per call to Search.results()
@Transactional public void setIdOnly()
@Transactional public void setMergedBatches(boolean merge)
Search
Search.results()
.setMergedBatches
in interface Search
@Transactional public void fetchAlso(String... fetches)
Search
@Transactional public boolean isAllowLeadingWildcard()
Search
Search.byFullText(String)
and
Search.bySomeMustNone(String[], String[], String[])
will throw an
ApiUsageException
, since leading-wildcard searches are quite
slow. Use Search.setAllowLeadingWildcard(boolean)
in order to permit
this usage.isAllowLeadingWildcard
in interface Search
@Transactional public boolean isReturnUnloaded()
Search
Search.setReturnUnloaded(boolean)
has not
been called, the default value
will be
in effect.isReturnUnloaded
in interface Search
@Transactional public boolean isUseProjections()
Search
for more.
If
Search.setUseProjections(boolean)
has not been called, the
Search.DEFAULT_USE_PROJECTIONS
will be in effect.isUseProjections
in interface Search
@Transactional public void onlyModifiedBetween(Timestamp start, Timestamp stop)
Search
onlyModifiedBetween
in interface Search
start
- Can be null, i.e. interval open to negative infinity.stop
- Can be null, i.e. interval open to positive infinity.@Transactional public void setCaseSentivice(boolean caseSensitive)
Search
setCaseSentivice
in interface Search
@Transactional public void setReturnUnloaded(boolean returnUnloaded)
Search
IQuery
. This value overrides the
Search.setUseProjections(boolean)
setting.setReturnUnloaded
in interface Search
@Transactional public void setUseProjections(boolean useProjections)
Search
setUseProjections
in interface Search
public void addAction(SearchAction action)
public void addParameters(Parameters params)
Version: 5.3.3-ice35-b63
Copyright © 2017 The University of Dundee & Open Microscopy Environment. All Rights Reserved.