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 A published renditions section will be sent in response with preset names and public S3 URLs as keys 51 * and values respectively if a license for renditions is enabled. 52 * /wf/restapi/v2/quickSearch 53 * 54 * Parameters: 55 * search=REST 56 * verbose=true 57 * fields=["http://purl.org/dc/elements/1.1/ contributor"] 58 * 59 Response: 60 [ 61 { 62 "id": 201629349, 63 "name": "REST.xmp", 64 "path": "REST.xmp", 65 "height": 1, 66 "width": 1, 67 "bytes": 2048, 68 "lastModified": 1508164732000, 69 "mimeType": "application/octet-stream", 70 "previews": { 71 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363239333439", 72 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363239333439", 73 "downloadUrl": "../servlet/dload?id=pe_323031363239333439" 74 }, 75 "publishedRenditions": { 76 "webPNG": "https://aws-cloud-host-s3Bucket/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a.png", 77 "webJpeg": "https://aws-cloud-host-s3Bucket/9ff45e98-dcc0-7823-9e45-c3be6390d3bf/9ff45e98-dcc0-7823-9e45-c3be6390d3bf.jpeg", 78 "webGif": "https://aws-cloud-host-s3Bucket/11a081b2-53cf-7823-bb08-2a7f75c4ccee/11a081b2-53cf-7823-bb08-2a7f75c4ccee.gif" 79 }, 80 "fields": { 81 "http://purl.org/dc/elements/1.1/ contributor": null 82 } 83 }, 84 { 85 "id": 201624280, 86 "name": "opo0123_orig.tif", 87 "path": "hubble/opo0123_orig.tif", 88 "height": 732, 89 "width": 1435, 90 "bytes": 3153629, 91 "lastModified": 1506953377000, 92 "mimeType": "image/tiff", 93 "previews": { 94 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323830", 95 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323830", 96 "downloadUrl": "../servlet/dload?id=pe_323031363234323830" 97 }, 98 "publishedRenditions": { 99 "webPNG": "https://aws-cloud-host-s3Bucket/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a.png", 100 "webJpeg": "https://aws-cloud-host-s3Bucket/9ff45e98-dcc0-7823-9e45-c3be6390d3bf/9ff45e98-dcc0-7823-9e45-c3be6390d3bf.jpeg", 101 "webGif": "https://aws-cloud-host-s3Bucket/11a081b2-53cf-7823-bb08-2a7f75c4ccee/11a081b2-53cf-7823-bb08-2a7f75c4ccee.gif" 102 }, 103 "fields": { 104 "http://purl.org/dc/elements/1.1/ contributor": [ 105 "REST" 106 ] 107 } 108 } 109 ] 110 111 * @example A published renditions section will be sent in response with preset names and public S3 URLs as keys 112 * and values respectively if a license for renditions is enabled. 113 * /wf/restapi/v2/quickSearch 114 * 115 * Parameters: 116 * search=REST 117 * directory=hubble/ 118 * verbose=true 119 * 120 Response: 121 [ 122 { 123 "id": 201624280, 124 "name": "opo0123_orig.tif", 125 "path": "hubble/opo0123_orig.tif", 126 "height": 732, 127 "width": 1435, 128 "bytes": 3153629, 129 "lastModified": 1506953377000, 130 "mimeType": "image/tiff", 131 "previews": { 132 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323830", 133 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323830", 134 "downloadUrl": "../servlet/dload?id=pe_323031363234323830" 135 }, 136 "publishedRenditions": { 137 "webPNG": "https://aws-cloud-host-s3Bucket/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a.png", 138 "webJpeg": "https://aws-cloud-host-s3Bucket/9ff45e98-dcc0-7823-9e45-c3be6390d3bf/9ff45e98-dcc0-7823-9e45-c3be6390d3bf.jpeg", 139 "webGif": "https://aws-cloud-host-s3Bucket/11a081b2-53cf-7823-bb08-2a7f75c4ccee/11a081b2-53cf-7823-bb08-2a7f75c4ccee.gif" 140 }, 141 "fields": { 142 "http://purl.org/dc/elements/1.1/ contributor": [ 143 "REST" 144 ] 145 } 146 } 147 ] 148 149 @example The data block filed will be sent in response if present in fields parameter 150 /wf/restapi/v2/quickSearch 151 152 Parameters: 153 search=REST 154 fields=["http://ns.mediabeacon.com/datablock/1.0/ datablock"] 155 verbose=true 156 157 Response: 158 [ 159 160 "id": 201633049, 161 "name": "SamplePNGImage_200kbmb.png", 162 "path": "upload/root/2023.04.28 14.00.31/SamplePNGImage_200kbmb.png", 163 "directoryId": 131, 164 "height": 250, 165 "width": 400, 166 "bytes": 515716, 167 "lastModified": 1682671155552, 168 "mimeType": "image/png", 169 "previews": { 170 "thumbnail": "../servlet/jb.view?table=thumbnails&col=thumbnails&id=pe_323031363234323830", 171 "viewex": "../servlet/jb.view?table=viewex&col=viewex&id=pe_323031363234323830", 172 "downloadUrl": "../servlet/dload?id=pe_323031363234323830" 173 }, 174 "publishedRenditions": { 175 "webPNG": "https://aws-cloud-host-s3Bucket/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a/c1ba4a79-2a82-7823-ab28-5a0a1fa8220a.png", 176 "webJpeg": "https://aws-cloud-host-s3Bucket/9ff45e98-dcc0-7823-9e45-c3be6390d3bf/9ff45e98-dcc0-7823-9e45-c3be6390d3bf.jpeg", 177 "webGif": "https://aws-cloud-host-s3Bucket/11a081b2-53cf-7823-bb08-2a7f75c4ccee/11a081b2-53cf-7823-bb08-2a7f75c4ccee.gif" 178 }, 179 "replaceDate": 0, 180 "versionNumber"{: 0, 181 "fields": { 182 "http://ns.mediabeacon.com/datablock/1.0/ datablock": [ 183 { 184 "http://ns.adobe.com/pdf/1.3/ Keywords": "REST" 185 } 186 ] 187 } 188 } 189 ] 190 */ 191 function main() { 192 mySearch = searchManager.createQuickSearch(context.getParameter("search")); 193 var aSearchDirectory = context.getParameter("directory"); 194 if (!!aSearchDirectory) { 195 mySearch = includeDirectory(mySearch, aSearchDirectory); 196 } 197 198 REST.setCallback(quickSearch); 199 return REST.execute(); 200 } 201 main();