1 var REST = library.REST.REST();
  2 var mySearch = null;
  3 
  4 /**
  5  * Adds the directory to the quickSearch
  6  * @param aSearch
  7  * @param theSearchDirectory
  8  */
  9 function includeDirectory(aSearch, theSearchDirectory) {
 10   var aPath = REST.getFullPath(theSearchDirectory);
 11   var aQSCriteria = aSearch.getCriteria();
 12   var aQSCriterion = aQSCriteria.getRootCriterion();
 13 
 14   var aDirectoryCriterion = new DatabaseCriterion("directory");
 15   aDirectoryCriterion.setCondition(searchManager.conditions.equals);
 16   aDirectoryCriterion.setValue(aPath);
 17   aQSCriteria.addCriterion(aDirectoryCriterion);
 18 
 19   var aFolderSpecificQuickSearch = new Criteria("AND");
 20   aFolderSpecificQuickSearch.addCriterion(aQSCriterion);
 21   aFolderSpecificQuickSearch.addCriterion(aDirectoryCriterion);
 22   aSearch.setCriteria(aFolderSpecificQuickSearch);
 23   return aSearch;
 24 }
 25 
 26 /**
 27  * Pushes the results into the response
 28  */
 29 function quickSearch() {
 30   var aResults = REST.executeSearchWithPaging(mySearch);
 31   for (var i in aResults) {
 32     REST.push(aResults[i], {}, true);
 33   }
 34 }
 35 
 36 /**
 37  * @name QuickSearch
 38  * @class Runs a quick search for assets.
 39  * @description Runs a quick search and displays the asset info for each result
 40  * @param search a string to search on.
 41  * @param [directory=theUsersRootDirectory] the directory path to limit the search results to.
 42  * @param [pageSize=100] the number of assets to give in the response
 43  * @param [pageIndex=0] the index of the page to return
 44  * @param [sortField] the namespace of the desired field ex "http://purl.org/dc/elements/1.1/ subject"
 45  * @param [sortDirection] "ASC" or "DESC".  the order in which the sortFiled should be applied
 46  * @param [verbose=false] Setting this to true will collect a variety of default values for each asset.
 47  * @param [FILTERS] Filtering can be applied to the "id", "name", "path", "height", "width", "bytes", "lastModified", "mimeType", and "resolver" properties if verbose=true.
 48  * @param [fields] An array of field id's to collect the values for each asset
 49  * @returns [{AssetData}, ... ]
 50  * @example /wf/restapi/v2/quickSearch
 51  *
 52  * Parameters:
 53  * search=REST
 54  * verbose=true
 55  * fields=["http://purl.org/dc/elements/1.1/ contributor"]
 56  *
 57  Response:
 58  [
 59 	 {
 60 	   "id": 201629349,
 61 	   "name": "REST.xmp",
 62 	   "path": "REST.xmp",
 63 	   "height": 1,
 64 	   "width": 1,
 65 	   "bytes": 2048,
 66 	   "lastModified": 1508164732000,
 67 	   "mimeType": "application/octet-stream",
 68 	   "previews": {
 69 		 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363239333439",
 70 		 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363239333439",
 71 		 "downloadUrl": "../servlet/dload?id=pe_323031363239333439"
 72 	   },
 73 	   "fields": {
 74 		 "http://purl.org/dc/elements/1.1/ contributor": null
 75 	   }
 76 	 },
 77 	 {
 78 	   "id": 201624280,
 79 	   "name": "opo0123_orig.tif",
 80 	   "path": "hubble/opo0123_orig.tif",
 81 	   "height": 732,
 82 	   "width": 1435,
 83 	   "bytes": 3153629,
 84 	   "lastModified": 1506953377000,
 85 	   "mimeType": "image/tiff",
 86 	   "previews": {
 87 		 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323830",
 88 		 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323830",
 89 		 "downloadUrl": "../servlet/dload?id=pe_323031363234323830"
 90 	   },
 91 	   "fields": {
 92 		 "http://purl.org/dc/elements/1.1/ contributor": [
 93 		   "REST"
 94 		 ]
 95 	   }
 96 	 }
 97  ]
 98 
 99  * @example /wf/restapi/v2/quickSearch
100  *
101  * Parameters:
102  * search=REST
103  * directory=hubble/
104  * verbose=true
105  *
106  Response:
107  [
108 	 {
109 	   "id": 201624280,
110 	   "name": "opo0123_orig.tif",
111 	   "path": "hubble/opo0123_orig.tif",
112 	   "height": 732,
113 	   "width": 1435,
114 	   "bytes": 3153629,
115 	   "lastModified": 1506953377000,
116 	   "mimeType": "image/tiff",
117 	   "previews": {
118 		 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323830",
119 		 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323830",
120 		 "downloadUrl": "../servlet/dload?id=pe_323031363234323830"
121 	   },
122 	   "fields": {
123 		 "http://purl.org/dc/elements/1.1/ contributor": [
124 		   "REST"
125 		 ]
126 	   }
127 	 }
128  ]
129  */
130 function main() {
131   mySearch = searchManager.createQuickSearch(context.getParameter("search"));
132   var aSearchDirectory = context.getParameter("directory");
133   if (!!aSearchDirectory) {
134     mySearch = includeDirectory(mySearch, aSearchDirectory);
135   }
136 
137   REST.setCallback(quickSearch);
138   return REST.execute();
139 }
140 main();
141