org.alfresco.repo.jscript
Class Search

java.lang.Object
  extended by org.alfresco.repo.processor.BaseProcessorExtension
      extended by org.alfresco.repo.jscript.BaseScopableProcessorExtension
          extended by org.alfresco.repo.jscript.Search
All Implemented Interfaces:
org.alfresco.processor.ProcessorExtension, Scopeable

public class Search
extends BaseScopableProcessorExtension

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);


Nested Class Summary
 class Search.SortColumn
          Search sort column
 
Field Summary
protected  Repository repository
          Repository helper
protected  ServiceRegistry services
          Service registry
protected  org.alfresco.service.cmr.repository.StoreRef storeRef
          Default store reference
 
Constructor Summary
Search()
           
 
Method Summary
 ScriptNode findNode(org.alfresco.service.cmr.repository.NodeRef ref)
          Find a single Node by the Node reference
 ScriptNode findNode(java.lang.String ref)
          Find a single Node by the Node reference
 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.
 java.lang.String ISO9075Decode(java.lang.String s)
          Decode a string from ISO9075
 java.lang.String ISO9075Encode(java.lang.String s)
          Encode a string to ISO9075 - used to build valid paths for Lucene queries etc.
 boolean isValidXpathQuery(java.lang.String query)
          Validation Xpath query
 org.mozilla.javascript.Scriptable luceneSearch(java.lang.String search)
          Execute a Lucene search
 org.mozilla.javascript.Scriptable luceneSearch(java.lang.String store, java.lang.String search)
          Execute a Lucene search
 org.mozilla.javascript.Scriptable luceneSearch(java.lang.String search, java.lang.String sortColumn, boolean asc)
          Execute a Lucene search (sorted)
 org.mozilla.javascript.Scriptable luceneSearch(java.lang.String search, java.lang.String sortColumn, boolean asc, int max)
           
 org.mozilla.javascript.Scriptable luceneSearch(java.lang.String store, java.lang.String search, java.lang.String sortColumn, boolean asc)
           
 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)
 org.mozilla.javascript.Scriptable query(java.lang.Object search)
          Execute a query based on the supplied search definition object.
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  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)
 org.mozilla.javascript.Scriptable savedSearch(ScriptNode savedSearch)
          Execute a saved Lucene search
 org.mozilla.javascript.Scriptable savedSearch(java.lang.String searchRef)
          Execute a saved Lucene search
 org.mozilla.javascript.Scriptable selectNodes(java.lang.String search)
          Execute a SelectNodes XPath search
 org.mozilla.javascript.Scriptable selectNodes(java.lang.String store, java.lang.String search)
          Execute a SelectNodes XPath search
 void setRepositoryHelper(Repository repository)
          Set the repository helper
 void setServiceRegistry(ServiceRegistry services)
          Set the service registry
 void setStoreUrl(java.lang.String storeRef)
          Set the default store reference
 ScriptNode[] tagSearch(java.lang.String store, java.lang.String tag)
          Searchs the store for all nodes with the given tag applied.
 org.mozilla.javascript.Scriptable xpathSearch(java.lang.String search)
          Execute a XPath search
 org.mozilla.javascript.Scriptable xpathSearch(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

Constructor Detail

Search

public Search()
Method Detail

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

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. 3) AVM Path - {store_id}/{path} Resolve to AVM node via its display path 4) QName - {store_type}/{store_id}/{child_qname_path} Resolve to node via its child qname path.

Parameters:
referenceType - one of node, path, avmpath or qname
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://SpacesStore
search - 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://SpacesStore
search - 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://SpacesStore
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 search,
                                                      java.lang.String sortColumn,
                                                      boolean asc)
Execute a Lucene search (sorted)

Parameters:
search - Lucene search string to execute
sortKey - property name to sort on
asc - 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://SpacesStore
search - Lucene search string to execute
sortKey - property name to sort on
asc - 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 provided
tag - 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, jcr-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
    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:
 http://wiki.alfresco.com/wiki/Full_Text_Search_Query_Syntax#Templates
 

Parameters:
search - Search definition object as above
Returns:
Array of ScriptNode results

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 store
search - Lucene search to execute
sort - Columns to sort by
language - 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 store
search - Lucene search to execute
sort - Columns to sort by
language - Search language to use e.g. SearchService.LANGUAGE_LUCENE
maxResults - Maximum results to return if > 0
skipResults - 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


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.