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);
and
var results = search.savedSearch(node);
- Author:
- Kevin Roast
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected RepositoryRepository helperprotected ServiceRegistryService registryprotected StoreRefDefault store reference -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFacetQuery(SearchParameters sp, String field, List<String> facetQueries, String query) Adds facet queries to theSearchParametersvoidFind a single Node by the Node referenceHelper 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.Find a single Node by the Node referencebooleangetBooleanValue(String attribute, boolean defaultValue, Map<Serializable, Serializable> sourceObject) Attempts to retrieve and parse an attribute in the supplied object to an integer.intgetIntegerValue(String attribute, int defaultValue, Map<Serializable, Serializable> sourceObject) Attempts to retrieve and parse an attribute in the supplied object to an integer.Decode a string from ISO9075Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.booleanisValidXpathQuery(String query) Validation Xpath queryorg.mozilla.javascript.ScriptableluceneSearch(String search) Execute a Lucene searchorg.mozilla.javascript.ScriptableluceneSearch(String store, String search) Execute a Lucene searchorg.mozilla.javascript.ScriptableluceneSearch(String search, String sortColumn, boolean asc) Execute a Lucene search (sorted)org.mozilla.javascript.ScriptableluceneSearch(String search, String sortColumn, boolean asc, int max) org.mozilla.javascript.ScriptableluceneSearch(String store, String search, String sortColumn, boolean asc) org.mozilla.javascript.ScriptableluceneSearch(String store, String search, String sortColumn, boolean asc, int max) Execute a Lucene search (sorted)org.mozilla.javascript.ScriptableExecute a query based on the supplied search definition object.protected Object[]query(String store, String search, Search.SortColumn[] sort, 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 Object[]query(String store, String search, Search.SortColumn[] sort, 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 Object[]query(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)queryResultMeta(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(Object search) org.mozilla.javascript.ScriptablesavedSearch(String searchRef) Execute a saved Lucene searchorg.mozilla.javascript.ScriptablesavedSearch(ScriptNode savedSearch) Execute a saved Lucene searchorg.mozilla.javascript.ScriptableselectNodes(String search) Execute a SelectNodes XPath searchorg.mozilla.javascript.ScriptableselectNodes(String store, String search) Execute a SelectNodes XPath searchvoidsetRepositoryHelper(Repository repository) Set the repository helpervoidsetSearchSubsystemSwitchableApplicationContextFactory(SwitchableApplicationContextFactory searchSubsystem) voidsetServiceRegistry(ServiceRegistry services) Set the service registryvoidsetStoreUrl(String storeRef) Set the default store referenceSearchs the store for all nodes with the given tag applied.org.mozilla.javascript.ScriptablexpathSearch(String search) Execute a XPath searchorg.mozilla.javascript.ScriptablexpathSearch(String store, String search) Execute a XPath searchMethods inherited from class org.alfresco.repo.jscript.BaseScopableProcessorExtension
getScope, setScopeMethods inherited from class org.alfresco.repo.processor.BaseProcessorExtension
getExtensionName, register, setExtensionName, setProcessor
-
Field Details
-
services
Service registry -
storeRef
Default store reference -
repository
Repository helper
-
-
Constructor Details
-
Search
public Search()
-
-
Method Details
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
setStoreUrl
Set the default store reference- Parameters:
storeRef- the default store reference
-
setServiceRegistry
Set the service registry- Parameters:
services- the service registry
-
setRepositoryHelper
Set the repository helper- Parameters:
repository- the repository helper
-
setSearchSubsystemSwitchableApplicationContextFactory
public void setSearchSubsystemSwitchableApplicationContextFactory(SwitchableApplicationContextFactory searchSubsystem) -
getSearchSubsystem
-
findNode
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
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
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
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
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
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
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
Validation Xpath query- Parameters:
query- xpath query- Returns:
- true if xpath query valid
-
luceneSearch
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
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(String search, 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
-
luceneSearch
-
luceneSearch
public org.mozilla.javascript.Scriptable luceneSearch(String store, String search, 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
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
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
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
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
-
getIntegerValue
public int getIntegerValue(String attribute, int defaultValue, Map<Serializable, 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(String attribute, boolean defaultValue, Map<Serializable, 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
Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.- Parameters:
s- Value to encode- Returns:
- encoded value
-
ISO9075Decode
Decode a string from ISO9075- Parameters:
s- Value to decode- Returns:
- decoded value
-
query
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 Object[] query(String store, String search, Search.SortColumn[] sort, 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
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 Pair<Object[],Map<String, queryResultMetaObject>> (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(SearchParameters sp, String field, List<String> facetQueries, String query) Adds facet queries to theSearchParameters- Parameters:
sp- the SearchParametersfield- the requested field facetfacetQueries- list of generated facet queriesquery- the requested search query
-