Search Query in Alfresco Javascript

We have seen in previous post how to create webscript. The example which we have seen was very basic now as per the complex requirement s we need to use the complex queries in the Javascript file to fetch the desired results.

I am just explaining few use cases here.

Case I:

Want all the results sorted by custom property we can use following query

var nodes = search.luceneSearch("Type:”custom:customtype”", "@custom:customproperty", false);

This method performs a Lucene search by particular content type and return result sorted by customproperty value in the given store.

 

Case II:

We have large number of contents with custom content type so we want to limit the resultset to specific size.

var nodes = search.luceneSearch("Type:”custom:customtype”", "@custom:customproperty", true, 25);

luceneSearch(store, search, sortColumn, asc, max) this method performs a Lucene search by property and a specified sort order in the give store. In above example we are limiting results to 25.

Parameters used:

Store: The given store ex. ( “workspace://SpacesStore”)

Search: The search terms and operators that represent the Lucene search phrase.

sortColumn: The property name to sort on

asc: The sort order. If set to true the results are ordered in ascending order based on the property specified. If false the results are sorted in descending order.

Max: The maximum number of items to return in the search results.

Case III:

Want to search through path query.

If (search.isValidXpathQuery(query)){

nodes = search.xpathSearch(query);

}

Case IV:

Search all the documents with specific tag ex. “mycustomtag”

var store = "workspace://SpacesStore";
var tag = "mycustomtag";
var nodes = search.tagSearch(store, tag);

These are few possible cases I have explained here. Hope this helps you in implementing your webscripts or Javascripts.

Looking for quality Alfresco Hosting?  Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight

mitpatoliya

mitpatoliya

I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

Leave a Reply

Your email address will not be published. Required fields are marked *


− 1 = 7

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>