Advanced search in WCM

The success of content management systems depends on its ability to locate the required content with fewer clicks. You will realize the benefits of having a powerful search engine when you have a large amount of content in your content management system.

Unlike many commercial content management systems, Alfresco includes a free and very powerful search engine called Lucene as part of installation. Hence you don't have to buy and install a third-party search engine. And moreover, you don't have to deal with integration issues and upgrades.

In Alfresco DM, you will be able to search both content and properties. You can do a full-text search on any word in content, regardless of the format. You can search for content in a particular space. You can also search for content belonging to certain categories or of a specific type. We will leverage this searching capability of Alfresco DM in WCM as well with the help of the Lucene search engine. In this section, we will see how we can use Lucene to search the content stored in Alfresco WCM and easily do a full-text search on any word in content, regardless of the format.

Searching in WCM is similar to the searching in DM, but in WCM, Lucene-based search is only possible in the Staging Sandbox. It is not possible for any User's Sandbox or also the Workflow Sandbox. XPath-based searching is possible for all the WCM stores including User's Sandbox and Workflow Sandbox. However, the drawback of XPath search is that the performance might slow down depending on the query and the store structure, as the implementation walks the object model.

WCM search can be performed via Java, JavaScript, FreeMarker template, or the Node Browser.

For more information on search, refer to http://wiki.alfresco.com/wiki/Search.

Using JavaScript

Using JavaScript API for search, you can search the content against WCM stores. Alfresco provides search as a root object for JavaScript, which provides access to Lucene search. The available APIs to perform search are:

  • luceneSearch(string query): This will perform a full-text Lucene search with the provided query and return the search result as an array of Script node objects.
  • luceneSearch(string store, string query): This will perform a full-text Lucene search in the specified store with the provided query and return the search result as an array of Script node objects.
  • luceneSearch(string query, string sortColumn, boolean asc): This will perform a full-text Lucene search with the provided query and return the sorted search result based on the column specified and the sorting order as an array of Script node objects.
  • luceneSearch(string store, string query, string sortColumn, boolean asc): This will perform a full-text Lucene search in the specified store with the provided query and return the sorted search result based on the column specified and the sorting order as an array of Script node objects.
  • xpathSearch(string xpath): This will perform an Alfresco XPath search and return the search result as an array of Script node objects.
  • xpathSearch(string store, string xpath): This will perform an Alfresco XPath search in the specified store and return the search result as an array of Script node objects.
  • ScriptNode findNode(NodeRef noderef): This will return a Script node for the specified noderef.
  • ScriptNode findNode(string noderef): This will return a Script node for the specified noderef in the form of String.

Here for the Lucene query, you can pass any valid Lucene query as an argument. While building the Lucene query, you can use multiple query criteria with combination of relational operator. For example, to search text "cignex", you can have the query as TEXT:cignex, as follows:

var results = search.luceneSearch("avm://wwwcignex","TEXT:cignex");

This will search for the text "cignex" in wwwcignex store (Staging Sandbox of the web project named wwwcignex).

Now if you want to restrict the search to some specific folder within the store, you can have path criteria in the query as PATH:"www/avm_webapps/ROOT/common//*", as follows:

var results = search.luceneSearch("avm://wwwcignex","TEXT:cignex" AND PATH:"www/avm_webapps/ROOT/common//*"");

AVM API to search in WCM store

Alfresco provides search APIs to perform search in the Alfresco Repository. The following is the API used to perform Lucene search in WCM.

  • store.luceneSearch(query): This will perform a Lucene search with the provided query against the store and return the search result as an array of AVM nodes.

To perform the search on a particular store, you need to get the store first and then you can execute search against that store, that is:

var store = avm.lookupStore("wwwcignex");
var results = store.luceneSearch("wca\:parentformname:news");

Using FreeMarker template

Similar to JavaScript, FreeMarker template language also provides the API to perform the search against the WCM stores; the API is:

  • store.luceneSearch(query): This will perform a Lucene search with the provided query against the store and return the search result as an array of AVM nodes.

For example, to search all the folders in the web project, you can have the query as follows:

<#assign store = avm.lookupStore("wwwcignex)>
<list store.luceneSearch(TYPE:"cm:folder") as l_search_result>
<li> ${l_search_result.properties.name} </li>
<#list>

Using the Node browser

You can use the Node browser available in Alfresco Explorer to search the content in the WCM stores. But only Admin users can have access to Node Browser. In order to use the Node browser:

  1. Click on the Administration Console button Using the Node browser the top menu bar.
  2. Click on the Node Browser option on the Administration console screen.
  3. It will have a list of all the stores of repository. Select the appropriate WCM store in which you want to perform the search.
  4. In the combo box for Search, select the Search Language, that is, lucene or xpath, and so on.
  5. In the Search text area, provide the search query for the specific language.
  6. Click on Search. It will perform the search and return the result nodes.
    Using the Node browser

Using Java

Java also provides Search Service to perform the search operations. The APIs available in search service to execute search are as follows:

  • query(Storeref store, String language, String query): This will search against the specified store in WCM with the given query and language.
  • query(Storeref store, String language, String query, QueryParameterDefinition[] queryParameterDefinition): This will search against the specified store in WCM with the given query language and Query Parameters. Here you can have a parameterized query.
  • query(Storeref store, Qname queryId, QueryParameter[] queryParameters): This will execute a canned query against the specified store with the given query identifier and query parameters.
  • query(SearchParameters searchParameters): This will perform search using the specified Search Parameters.

All of the previous APIs for search using search service available in Alfresco will return Search results as a ResultSet. You can iterate this result set and perform any further processing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset