Package org.alfresco.repo.jscript
Class Search
- java.lang.Object
-
- org.alfresco.repo.processor.BaseProcessorExtension
-
- org.alfresco.repo.jscript.BaseScopableProcessorExtension
-
- org.alfresco.repo.jscript.Search
-
- All Implemented Interfaces:
org.alfresco.processor.ProcessorExtension,Scopeable,org.springframework.beans.factory.InitializingBean
public class Search extends BaseScopableProcessorExtension implements org.springframework.beans.factory.InitializingBean
Search component for use by the ScriptService.Provides access to Lucene search facilities including saved search objects. The results from a search are returned as an array (collection) of scriptable Node wrapper objects.
The object is added to the root of the model to provide syntax such as:
var results = search.luceneSearch(statement);andvar results = search.savedSearch(node);- Author:
- Kevin Roast
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSearch.SortColumnSearch sort column
-
Field Summary
Fields Modifier and Type Field Description protected RepositoryrepositoryRepository helperprotected ServiceRegistryservicesService registryprotected org.alfresco.service.cmr.repository.StoreRefstoreRefDefault store reference
-
Constructor Summary
Constructors Constructor Description Search()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddFacetQuery(org.alfresco.service.cmr.search.SearchParameters sp, java.lang.String field, java.util.List<java.lang.String> facetQueries, java.lang.String query)Adds facet queries to theSearchParametersvoidafterPropertiesSet()ScriptNodefindNode(java.lang.String ref)Find a single Node by the Node referenceScriptNodefindNode(java.lang.String referenceType, java.lang.String[] reference)Helper to convert a Web Script Request URL to a Node Ref 1) Node - {store_type}/{store_id}/{node_id} Resolve to node via its Node Reference.ScriptNodefindNode(org.alfresco.service.cmr.repository.NodeRef ref)Find a single Node by the Node referencebooleangetBooleanValue(java.lang.String attribute, boolean defaultValue, java.util.Map<java.io.Serializable,java.io.Serializable> sourceObject)Attempts to retrieve and parse an attribute in the supplied object to an integer.intgetIntegerValue(java.lang.String attribute, int defaultValue, java.util.Map<java.io.Serializable,java.io.Serializable> sourceObject)Attempts to retrieve and parse an attribute in the supplied object to an integer.java.lang.StringgetSearchSubsystem()java.lang.StringISO9075Decode(java.lang.String s)Decode a string from ISO9075java.lang.StringISO9075Encode(java.lang.String s)Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.booleanisValidXpathQuery(java.lang.String query)Validation Xpath queryorg.mozilla.javascript.ScriptableluceneSearch(java.lang.String search)Execute a Lucene searchorg.mozilla.javascript.ScriptableluceneSearch(java.lang.String store, java.lang.String search)Execute a Lucene searchorg.mozilla.javascript.ScriptableluceneSearch(java.lang.String search, java.lang.String sortColumn, boolean asc)Execute a Lucene search (sorted)org.mozilla.javascript.ScriptableluceneSearch(java.lang.String search, java.lang.String sortColumn, boolean asc, int max)org.mozilla.javascript.ScriptableluceneSearch(java.lang.String store, java.lang.String search, java.lang.String sortColumn, boolean asc)org.mozilla.javascript.ScriptableluceneSearch(java.lang.String store, java.lang.String search, java.lang.String sortColumn, boolean asc, int max)Execute a Lucene search (sorted)org.mozilla.javascript.Scriptablequery(java.lang.Object search)Execute a query based on the supplied search definition object.protected java.lang.Object[]query(java.lang.String store, java.lang.String search, Search.SortColumn[] sort, java.lang.String language)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)protected java.lang.Object[]query(java.lang.String store, java.lang.String search, Search.SortColumn[] sort, java.lang.String language, int maxResults, int skipResults)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)protected java.lang.Object[]query(org.alfresco.service.cmr.search.SearchParameters sp, boolean exceptionOnError)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)protected org.alfresco.util.Pair<java.lang.Object[],java.util.Map<java.lang.String,java.lang.Object>>queryResultMeta(org.alfresco.service.cmr.search.SearchParameters sp, boolean exceptionOnError)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)org.mozilla.javascript.ScriptablequeryResultSet(java.lang.Object search)org.mozilla.javascript.ScriptablesavedSearch(java.lang.String searchRef)Execute a saved Lucene searchorg.mozilla.javascript.ScriptablesavedSearch(ScriptNode savedSearch)Execute a saved Lucene searchorg.mozilla.javascript.ScriptableselectNodes(java.lang.String search)Execute a SelectNodes XPath searchorg.mozilla.javascript.ScriptableselectNodes(java.lang.String store, java.lang.String search)Execute a SelectNodes XPath searchvoidsetRepositoryHelper(Repository repository)Set the repository helpervoidsetSearchSubsystemSwitchableApplicationContextFactory(SwitchableApplicationContextFactory searchSubsystem)voidsetServiceRegistry(ServiceRegistry services)Set the service registryvoidsetStoreUrl(java.lang.String storeRef)Set the default store referenceScriptNode[]tagSearch(java.lang.String store, java.lang.String tag)Searchs the store for all nodes with the given tag applied.org.mozilla.javascript.ScriptablexpathSearch(java.lang.String search)Execute a XPath searchorg.mozilla.javascript.ScriptablexpathSearch(java.lang.String store, java.lang.String search)Execute a XPath search-
Methods inherited from class org.alfresco.repo.jscript.BaseScopableProcessorExtension
getScope, setScope
-
Methods inherited from class org.alfresco.repo.processor.BaseProcessorExtension
getExtensionName, register, setExtensionName, setProcessor
-
-
-
-
Field Detail
-
services
protected ServiceRegistry services
Service registry
-
storeRef
protected org.alfresco.service.cmr.repository.StoreRef storeRef
Default store reference
-
repository
protected Repository repository
Repository helper
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception
-
setStoreUrl
public void setStoreUrl(java.lang.String storeRef)
Set the default store reference- Parameters:
storeRef- the default store reference
-
setServiceRegistry
public void setServiceRegistry(ServiceRegistry services)
Set the service registry- Parameters:
services- the service registry
-
setRepositoryHelper
public void setRepositoryHelper(Repository repository)
Set the repository helper- Parameters:
repository- the repository helper
-
setSearchSubsystemSwitchableApplicationContextFactory
public void setSearchSubsystemSwitchableApplicationContextFactory(SwitchableApplicationContextFactory searchSubsystem)
-
getSearchSubsystem
public java.lang.String getSearchSubsystem()
-
findNode
public ScriptNode findNode(org.alfresco.service.cmr.repository.NodeRef ref)
Find a single Node by the Node reference- Parameters:
ref- The NodeRef of the Node to find- Returns:
- the Node if found or null if failed to find
-
findNode
public ScriptNode findNode(java.lang.String ref)
Find a single Node by the Node reference- Parameters:
ref- The fully qualified NodeRef in String format- Returns:
- the Node if found or null if failed to find
-
findNode
public ScriptNode findNode(java.lang.String referenceType, java.lang.String[] reference)
Helper to convert a Web Script Request URL to a Node Ref 1) Node - {store_type}/{store_id}/{node_id} Resolve to node via its Node Reference. 2) Path - {store_type}/{store_id}/{path} Resolve to node via its display path.- Parameters:
referenceType- one of "node", "path"reference- array of reference segments (as described above for each reference type)- Returns:
- ScriptNode the script node
-
xpathSearch
public org.mozilla.javascript.Scriptable xpathSearch(java.lang.String search)
Execute a XPath search- Parameters:
search- XPath search string to execute- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
xpathSearch
public org.mozilla.javascript.Scriptable xpathSearch(java.lang.String store, java.lang.String search)Execute a XPath search- Parameters:
store- Store reference to search against i.e. workspace://SpacesStoresearch- XPath search string to execute- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
selectNodes
public org.mozilla.javascript.Scriptable selectNodes(java.lang.String search)
Execute a SelectNodes XPath search- Parameters:
search- SelectNodes XPath search string to execute- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
selectNodes
public org.mozilla.javascript.Scriptable selectNodes(java.lang.String store, java.lang.String search)Execute a SelectNodes XPath search- Parameters:
store- Store reference to search against i.e. workspace://SpacesStoresearch- SelectNodes XPath search string to execute- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
isValidXpathQuery
public boolean isValidXpathQuery(java.lang.String query)
Validation Xpath query- Parameters:
query- xpath query- Returns:
- true if xpath query valid
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(java.lang.String search)
Execute a Lucene search- Parameters:
search- Lucene search string to execute- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(java.lang.String store, java.lang.String search)Execute a Lucene search- Parameters:
store- Store reference to search against i.e. workspace://SpacesStoresearch- Lucene search string to execute- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(java.lang.String search, java.lang.String sortColumn, boolean asc)Execute a Lucene search (sorted)- Parameters:
search- Lucene search string to executesortColumn- column to sort onasc- true => ascending sort- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(java.lang.String search, java.lang.String sortColumn, boolean asc, int max)
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(java.lang.String store, java.lang.String search, java.lang.String sortColumn, boolean asc)
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(java.lang.String store, java.lang.String search, java.lang.String sortColumn, boolean asc, int max)Execute a Lucene search (sorted)- Parameters:
store- Store reference to search against i.e. workspace://SpacesStoresearch- Lucene search string to executesortColumn- column to sort onasc- true => ascending sort- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
savedSearch
public org.mozilla.javascript.Scriptable savedSearch(ScriptNode savedSearch)
Execute a saved Lucene search- Parameters:
savedSearch- Node that contains the saved search XML content- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
savedSearch
public org.mozilla.javascript.Scriptable savedSearch(java.lang.String searchRef)
Execute a saved Lucene search- Parameters:
searchRef- NodeRef string that points to the node containing saved search XML content- Returns:
- JavaScript array of Node results from the search - can be empty but not null
-
tagSearch
public ScriptNode[] tagSearch(java.lang.String store, java.lang.String tag)
Searchs the store for all nodes with the given tag applied.- Parameters:
store- store ref string, default used if null providedtag- tag name- Returns:
- ScriptNode[] nodes with tag applied
-
query
public org.mozilla.javascript.Scriptable query(java.lang.Object search)
Execute a query based on the supplied search definition object. Search object is defined in JavaScript thus:search { query: string, mandatory, in appropriate format and encoded for the given language store: string, optional, defaults to 'workspace://SpacesStore' language: string, optional, one of: lucene, xpath, fts-alfresco - defaults to 'lucene' templates: [], optional, Array of query language template objects (see below) - if supported by the language sort: [], optional, Array of sort column objects (see below) - if supported by the language page: object, optional, paging information object (see below) - if supported by the language namespace: string, optional, the default namespace for properties defaultField: string, optional, the default field for query elements when not explicit in the query defaultOperator: string,optional, the default operator for query elements when they are not explicit in the query AND or OR fieldFacets: [], optional, Array of fields (as full QName strings) to facet against onerror: string optional, result on error - one of: exception, no-results - defaults to 'exception' } sort { column: string, mandatory, sort column in appropriate format for the language ascending: boolean optional, defaults to false } page { maxItems: int, optional, max number of items to return in result set skipCount: int optional, number of items to skip over before returning results } template { field: string, mandatory, custom field name for the template template: string mandatory, query template replacement for the template } Note that only some query languages support custom query templates, such as 'fts-alfresco'. See the following documentation for more details: Templates- Parameters:
search- Search definition object as above- Returns:
- Array of ScriptNode results
-
queryResultSet
public org.mozilla.javascript.Scriptable queryResultSet(java.lang.Object search)
-
getIntegerValue
public int getIntegerValue(java.lang.String attribute, int defaultValue, java.util.Map<java.io.Serializable,java.io.Serializable> sourceObject)Attempts to retrieve and parse an attribute in the supplied object to an integer. If the attribute cannot be found or cannot be parsed then the supplied default is returned.- Parameters:
attribute-defaultValue-sourceObject-- Returns:
-
getBooleanValue
public boolean getBooleanValue(java.lang.String attribute, boolean defaultValue, java.util.Map<java.io.Serializable,java.io.Serializable> sourceObject)Attempts to retrieve and parse an attribute in the supplied object to an integer. If the attribute cannot be found or cannot be parsed then the supplied default is returned.- Parameters:
attribute-defaultValue-sourceObject-- Returns:
-
ISO9075Encode
public java.lang.String ISO9075Encode(java.lang.String s)
Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.- Parameters:
s- Value to encode- Returns:
- encoded value
-
ISO9075Decode
public java.lang.String ISO9075Decode(java.lang.String s)
Decode a string from ISO9075- Parameters:
s- Value to decode- Returns:
- decoded value
-
query
protected java.lang.Object[] query(java.lang.String store, java.lang.String search, Search.SortColumn[] sort, java.lang.String language)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)- Parameters:
store- StoreRef to search against - null for default configured storesearch- Lucene search to executesort- Columns to sort bylanguage- Search language to use e.g. SearchService.LANGUAGE_LUCENE- Returns:
- Array of Node objects
-
query
protected java.lang.Object[] query(java.lang.String store, java.lang.String search, Search.SortColumn[] sort, java.lang.String language, int maxResults, int skipResults)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)- Parameters:
store- StoreRef to search against - null for default configured storesearch- Lucene search to executesort- Columns to sort bylanguage- Search language to use e.g. SearchService.LANGUAGE_LUCENEmaxResults- Maximum results to return if > 0skipResults- Results to skip in the result set- Returns:
- Array of Node objects
-
query
protected java.lang.Object[] query(org.alfresco.service.cmr.search.SearchParameters sp, boolean exceptionOnError)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)- Parameters:
sp- SearchParameters describing the search to execute.exceptionOnError- True to throw a runtime exception on error, false to return empty resultset- Returns:
- Array of Node objects
-
queryResultMeta
protected org.alfresco.util.Pair<java.lang.Object[],java.util.Map<java.lang.String,java.lang.Object>> queryResultMeta(org.alfresco.service.cmr.search.SearchParameters sp, boolean exceptionOnError)Execute the query Removes any duplicates that may be present (ID search can cause duplicates - it is better to remove them here)- Parameters:
sp- SearchParameters describing the search to execute.exceptionOnError- True to throw a runtime exception on error, false to return empty resultset- Returns:
- Pair containing Object[] of Node objects, and the ResultSet metadata hash.
-
addFacetQuery
protected void addFacetQuery(org.alfresco.service.cmr.search.SearchParameters sp, java.lang.String field, java.util.List<java.lang.String> facetQueries, java.lang.String query)Adds facet queries to theSearchParameters- Parameters:
sp- the SearchParametersfield- the requested field facetfacetQueries- list of generated facet queriesquery- the requested search query
-
-