public class Search extends BaseScopableProcessorExtension implements org.springframework.beans.factory.InitializingBean
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);
Modifier and Type | Class and Description |
---|---|
class |
Search.SortColumn
Search sort column
|
Modifier and Type | Field and Description |
---|---|
protected Repository |
repository
Repository helper
|
protected ServiceRegistry |
services
Service registry
|
protected org.alfresco.service.cmr.repository.StoreRef |
storeRef
Default store reference
|
Constructor and Description |
---|
Search() |
Modifier and Type | Method and Description |
---|---|
protected void |
addFacetQuery(org.alfresco.service.cmr.search.SearchParameters sp,
String field,
List<String> facetQueries,
String query)
Adds facet queries to the
SearchParameters |
void |
afterPropertiesSet() |
ScriptNode |
findNode(org.alfresco.service.cmr.repository.NodeRef ref)
Find a single Node by the Node reference
|
ScriptNode |
findNode(String ref)
Find a single Node by the Node reference
|
ScriptNode |
findNode(String referenceType,
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.
|
boolean |
getBooleanValue(String attribute,
boolean defaultValue,
Map<Serializable,Serializable> sourceObject)
Attempts to retrieve and parse an attribute in the supplied object to an integer.
|
int |
getIntegerValue(String attribute,
int defaultValue,
Map<Serializable,Serializable> sourceObject)
Attempts to retrieve and parse an attribute in the supplied object to an integer.
|
String |
getSearchSubsystem() |
String |
ISO9075Decode(String s)
Decode a string from ISO9075
|
String |
ISO9075Encode(String s)
Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.
|
boolean |
isValidXpathQuery(String query)
Validation Xpath query
|
org.mozilla.javascript.Scriptable |
luceneSearch(String search)
Execute a Lucene search
|
org.mozilla.javascript.Scriptable |
luceneSearch(String store,
String search)
Execute a Lucene search
|
org.mozilla.javascript.Scriptable |
luceneSearch(String search,
String sortColumn,
boolean asc)
Execute a Lucene search (sorted)
|
org.mozilla.javascript.Scriptable |
luceneSearch(String search,
String sortColumn,
boolean asc,
int max) |
org.mozilla.javascript.Scriptable |
luceneSearch(String store,
String search,
String sortColumn,
boolean asc) |
org.mozilla.javascript.Scriptable |
luceneSearch(String store,
String search,
String sortColumn,
boolean asc,
int max)
Execute a Lucene search (sorted)
|
org.mozilla.javascript.Scriptable |
query(Object search)
Execute a query based on the supplied search definition object.
|
protected 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 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 org.alfresco.util.Pair<Object[],Map<String,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.Scriptable |
queryResultSet(Object search) |
org.mozilla.javascript.Scriptable |
savedSearch(ScriptNode savedSearch)
Execute a saved Lucene search
|
org.mozilla.javascript.Scriptable |
savedSearch(String searchRef)
Execute a saved Lucene search
|
org.mozilla.javascript.Scriptable |
selectNodes(String search)
Execute a SelectNodes XPath search
|
org.mozilla.javascript.Scriptable |
selectNodes(String store,
String search)
Execute a SelectNodes XPath search
|
void |
setRepositoryHelper(Repository repository)
Set the repository helper
|
void |
setSearchSubsystemSwitchableApplicationContextFactory(SwitchableApplicationContextFactory searchSubsystem) |
void |
setServiceRegistry(ServiceRegistry services)
Set the service registry
|
void |
setStoreUrl(String storeRef)
Set the default store reference
|
ScriptNode[] |
tagSearch(String store,
String tag)
Searchs the store for all nodes with the given tag applied.
|
org.mozilla.javascript.Scriptable |
xpathSearch(String search)
Execute a XPath search
|
org.mozilla.javascript.Scriptable |
xpathSearch(String store,
String search)
Execute a XPath search
|
getScope, setScope
getExtensionName, register, setExtensionName, setProcessor
protected ServiceRegistry services
protected org.alfresco.service.cmr.repository.StoreRef storeRef
protected Repository repository
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public void setStoreUrl(String storeRef)
storeRef
- the default store referencepublic void setServiceRegistry(ServiceRegistry services)
services
- the service registrypublic void setRepositoryHelper(Repository repository)
repository
- the repository helperpublic void setSearchSubsystemSwitchableApplicationContextFactory(SwitchableApplicationContextFactory searchSubsystem)
public String getSearchSubsystem()
public ScriptNode findNode(org.alfresco.service.cmr.repository.NodeRef ref)
ref
- The NodeRef of the Node to findpublic ScriptNode findNode(String ref)
ref
- The fully qualified NodeRef in String formatpublic ScriptNode findNode(String referenceType, String[] reference)
referenceType
- one of "node", "path"reference
- array of reference segments (as described above for each reference type)public org.mozilla.javascript.Scriptable xpathSearch(String search)
search
- XPath search string to executepublic org.mozilla.javascript.Scriptable xpathSearch(String store, String search)
store
- Store reference to search against i.e. workspace://SpacesStoresearch
- XPath search string to executepublic org.mozilla.javascript.Scriptable selectNodes(String search)
search
- SelectNodes XPath search string to executepublic org.mozilla.javascript.Scriptable selectNodes(String store, String search)
store
- Store reference to search against i.e. workspace://SpacesStoresearch
- SelectNodes XPath search string to executepublic boolean isValidXpathQuery(String query)
query
- xpath querypublic org.mozilla.javascript.Scriptable luceneSearch(String search)
search
- Lucene search string to executepublic org.mozilla.javascript.Scriptable luceneSearch(String store, String search)
store
- Store reference to search against i.e. workspace://SpacesStoresearch
- Lucene search string to executepublic org.mozilla.javascript.Scriptable luceneSearch(String search, String sortColumn, boolean asc)
search
- Lucene search string to executesortColumn
- column to sort onasc
- true => ascending sortpublic org.mozilla.javascript.Scriptable luceneSearch(String search, String sortColumn, boolean asc, int max)
public org.mozilla.javascript.Scriptable luceneSearch(String store, String search, String sortColumn, boolean asc)
public org.mozilla.javascript.Scriptable luceneSearch(String store, String search, String sortColumn, boolean asc, int max)
store
- Store reference to search against i.e. workspace://SpacesStoresearch
- Lucene search string to executesortColumn
- column to sort onasc
- true => ascending sortpublic org.mozilla.javascript.Scriptable savedSearch(ScriptNode savedSearch)
savedSearch
- Node that contains the saved search XML contentpublic org.mozilla.javascript.Scriptable savedSearch(String searchRef)
searchRef
- NodeRef string that points to the node containing saved search XML contentpublic ScriptNode[] tagSearch(String store, String tag)
store
- store ref string, default used if null providedtag
- tag namepublic org.mozilla.javascript.Scriptable query(Object search)
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
search
- Search definition object as abovepublic org.mozilla.javascript.Scriptable queryResultSet(Object search)
public int getIntegerValue(String attribute, int defaultValue, Map<Serializable,Serializable> sourceObject)
attribute
- defaultValue
- sourceObject
- public boolean getBooleanValue(String attribute, boolean defaultValue, Map<Serializable,Serializable> sourceObject)
attribute
- defaultValue
- sourceObject
- public String ISO9075Encode(String s)
s
- Value to encodepublic String ISO9075Decode(String s)
s
- Value to decodeprotected Object[] query(String store, String search, Search.SortColumn[] sort, String language)
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_LUCENEprotected Object[] query(String store, String search, Search.SortColumn[] sort, String language, int maxResults, int skipResults)
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 setprotected Object[] query(org.alfresco.service.cmr.search.SearchParameters sp, boolean exceptionOnError)
sp
- SearchParameters describing the search to execute.exceptionOnError
- True to throw a runtime exception on error, false to return empty resultsetprotected org.alfresco.util.Pair<Object[],Map<String,Object>> queryResultMeta(org.alfresco.service.cmr.search.SearchParameters sp, boolean exceptionOnError)
sp
- SearchParameters describing the search to execute.exceptionOnError
- True to throw a runtime exception on error, false to return empty resultsetprotected void addFacetQuery(org.alfresco.service.cmr.search.SearchParameters sp, String field, List<String> facetQueries, String query)
SearchParameters
sp
- the SearchParametersfield
- the requested field facetfacetQueries
- list of generated facet queriesquery
- the requested search queryCopyright © 2005–2017 Alfresco Software. All rights reserved.