( projectNumber = 'YOUR_PROJECT_NUMBER', location = 'YOUR_PROJECT_LOCATION', userId = 'user:xxx@example.com', documentQueryText = 'YOUR_DOCUMENT_QUERY' )
| 15 | |
| 16 | 'use strict'; |
| 17 | async function main( |
| 18 | projectNumber = 'YOUR_PROJECT_NUMBER', |
| 19 | location = 'YOUR_PROJECT_LOCATION', |
| 20 | userId = 'user:xxx@example.com', |
| 21 | documentQueryText = 'YOUR_DOCUMENT_QUERY' |
| 22 | ) { |
| 23 | // [START contentwarehouse_search_documents] |
| 24 | /** |
| 25 | * TODO(developer): Uncomment these variables before running the sample. |
| 26 | * const projectNumber = 'YOUR_PROJECT_NUMBER'; |
| 27 | * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu' |
| 28 | * const userId = 'user:xxx@example.com'; // Format is "user:xxx@example.com" |
| 29 | * const documentQueryText = 'YOUR_DOCUMENT_QUERY' |
| 30 | */ |
| 31 | |
| 32 | // Import from google cloud |
| 33 | const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1; |
| 34 | |
| 35 | const apiEndpoint = |
| 36 | location === 'us' |
| 37 | ? 'contentwarehouse.googleapis.com' |
| 38 | : `${location}-contentwarehouse.googleapis.com`; |
| 39 | |
| 40 | // Create service client |
| 41 | const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint}); |
| 42 | |
| 43 | // Get Document Schema |
| 44 | async function searchDocuments() { |
| 45 | // Initialize request argument(s) |
| 46 | const searchRequest = { |
| 47 | // The full resource name of the location, e.g.: |
| 48 | // projects/{project_number}/locations/{location} |
| 49 | parent: `projects/${projectNumber}/locations/${location}`, |
| 50 | |
| 51 | // Document Text Query |
| 52 | documentQuery: { |
| 53 | query: documentQueryText, |
| 54 | // File Type Filter |
| 55 | fileTypeFilter: { |
| 56 | fileType: 'DOCUMENT', |
| 57 | }, |
| 58 | }, |
| 59 | |
| 60 | // Histogram Query |
| 61 | histogramQueries: [ |
| 62 | { |
| 63 | histogramQuery: 'count("DocumentSchemaId")', |
| 64 | }, |
| 65 | ], |
| 66 | requestMetadata: {userInfo: {id: userId}}, |
| 67 | }; |
| 68 | |
| 69 | // Make Request |
| 70 | const response = serviceClient.searchDocuments(searchRequest); |
| 71 | |
| 72 | // Print out response |
| 73 | response.then( |
| 74 | result => console.log(`Document Found: ${JSON.stringify(result)}`), |
no test coverage detected