Class: Alfresco::SearchApi
- Inherits:
-
Object
- Object
- Alfresco::SearchApi
- Defined in:
- lib/alfresco/api/search_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#initialize(api_client = ApiClient.default) ⇒ SearchApi
constructor
A new instance of SearchApi.
-
#search(query_body, opts = {}) ⇒ ResultSetPaging
Searches Alfresco Note: this endpoint is available in Alfresco 5.2 and newer versions.
-
#search_with_http_info(query_body, opts = {}) ⇒ Array<(ResultSetPaging, Fixnum, Hash)>
Searches Alfresco Note: this endpoint is available in Alfresco 5.2 and newer versions.
Constructor Details
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
17 18 19 |
# File 'lib/alfresco/api/search_api.rb', line 17 def api_client @api_client end |
Instance Method Details
#search(query_body, opts = {}) ⇒ ResultSetPaging
Searches Alfresco Note: this endpoint is available in Alfresco 5.2 and newer versions. **You specify all the parameters in this API in a JSON body**, URL parameters are not supported. A basic query looks like this: “‘JSON { "query": { "query": "foo" } } “` Note: These are the minimum possible query parameters. The default search language is afts ([Alfresco Full Text Search](docs.alfresco.com/5.1/concepts/rm-searchsyntax-intro.html)), but you can also specify cmis, and lucene. A basic CMIS query looks like this: “`JSON { "query": { "query": "select * from cmis:folder", "language": "cmis" } } “` By default, **results are limited to the first 100.** Results can be restricted using "paging". For example: “`JSON "paging": { "maxItems": "50", "skipCount": "28" } “` This example would ensure that results are **limited by Final Size**, skipping the first 28 results and returning the next 50. Alternatively, you can limit the results by using the **limits JSON body parameter**. For example, “`JSON "limits": { "permissionEvaluationTime": 20000, "permissionEvaluationCount": 2000 } “` You can use the **include JSON body parameter** to return additional information. This works in the same way as in the /nodes/nodeId/children method in the core API. For example: “`JSON "include": ["aspectNames", "properties", "isLink"] “` You can use the **fields JSON body parameter** to restrict the fields returned within a response if, for example, you want to save on overall bandwidth. This works in the same way as in the /nodes/nodeId/children method in the core API. For example: “`JSON "fields": ["id", "name", "search"] “` You can sort the results using the **sort JSON body parameter**, for example: “`JSON "sort": ["field":"cm:description", "ascending":"true"] “` Note: the sort parameter is not supported for CMIS queries. By default, search uses the **"nodes" location**, which is the **content store known as workspace://SpacesStore**. To change the scope to another location you can use the **locations JSON body parameter**. You can specify either nodes (the default), versions or deleted-nodes. For example, “`JSON "scope": { "locations": ["deleted-nodes"] } “` You can specify templates using the **templates JSON body parameter**, for example: “`JSON "templates": ["_PERSON","template": "|%firstName OR |%lastName OR |%userName", "mytemplate","template": "%cm:content"] “` **Note: Spell checking only works on Search Services (Solr 6) if you have already enabled suggestions.** For **spell checking** you can use a query like this: “`JSON { "query": { "query": "cm:title:alfrezco" }, "spellcheck": "alfrezco" } “` If you are already specifying "userQuery" then the following may be easier and produces the same result : “`JSON { "query": { "query": "cm:title:alfrezco", "userQuery": "alfrezco" }, "spellcheck": {} } “` The spellcheck response includes a spellCheck context like this: “`JSON "context": { "spellCheck": { "type": "searchInsteadFor", "suggestions": ["alfresco"] } }, “` To specify defaults, you use a **defaults JSON body parameter**, for example: “`JSON "defaults": { "textAttributes": [ "cm:content", "cm:name" ], "defaultFTSOperator": "AND", "defaultFTSFieldOperator": "OR", "namespace": "cm", "defaultFieldName": "PATH" } “` You can specify several filter queries using the **filterQueries JSON body parameter**, for example: “`JSON "filterQueries": ["TYPE:’cm:folder’","cm:creator:mjackson"] “‘ You can specify several facet queries using the **facetQueries JSON body parameter**, for example: “`JSON "facetQueries": ["created:2016","label": "CreatedThisYear"] “` The response will contain a matching "context" section, the "label" will match the facet query. “`JSON "context": { "facetQueries": [ "CreatedThisYear","count": 3 ] }, “` A complete query for facetting via the content.size field looks this: “`JSON { "query": { "query": "presentation", "language": "afts" }, "facetQueries": [ "content.size:[0 TO 10240]", "label": "xtra small", "content.size:[10240 TO 102400]", "label": "small", "content.size:[102400 TO 1048576]", "label": "medium", "content.size:[1048576 TO 16777216]", "label": "large", "content.size:[16777216 TO 134217728]", "label": "xtra large", "content.size:[134217728 TO MAX]", "label": "XX large" ], "facetFields": [{"field": "’content.size’"]} } “‘ The response will contain a matching "context" section, the "label" will match the facet query. “`JSON "context": { "facetQueries": [ { "label": "small","count": 2 }, { "label": "large","count": 0 }, { "label": "xtra small","count": 5 }, { "label": "xtra large","count": 56}, { "label": "medium","count": 4 }, { "label": "XX large", "count": 1 } ] }, “` You can specify several facet fields using the **facetFields JSON body parameter**, for example: “`JSON "facetFields": [{"field": "creator", "mincount": 1, "modifier", "mincount": 1]} “` The response will contain a matching "context" section, the "label" will match the facet field. “`JSON "context": { "facetsFields": [ { "label": "creator", "buckets": [ { "label": "System", "count": 75 }, { "label": "mjackson", "count": 5 } ]}, { "label": "modifier", "buckets": [ { "label": "System", "count": 72 }, { "label": "mjackson", "count": 5 }, { "label": "admin", "count": 3 } ]} ] }, “` Grouping facet queries that go together can be done by specifying the group label in the fact queries as follow: “`JSON { "query": { "query": "presentation" }, "facetQueries": [ "content.size:[0 TO 102400]", "label": "small", "group":"foo", "content.size:[102400 TO 1048576]", "label": "medium","group":"foo", "content.size:[1048576 TO 16777216]", "label": "large","group":"foo" ] } “` The above query returns the results a faceted field grouped under the label foo: “`JSON { "context": {"facetsFields": [{ "label": "foo", "buckets": [ { "count": 109, "label": "small", "filterQuery": "content.size:[0 TO 102400]" }, { "count": 0, "label": "large", "filterQuery": "content.size:[1048576 TO 16777216]" }, { "count": 0, "label": "medium", "filterQuery": "content.size:[102400 TO 1048576]" } ] }] } “` Range Faceting is supported by the **ranges JSON body parameter**, for example: “`JSON { "query": { "query": "presentation" }, "ranges": [ { "field": "content.size", "start": "0", "end": "100", "gap": "20", "hardend": true }, { "field": "created", "start": "2015-09-29T10:45:15.729Z", "end": "2016-09-29T10:45:15.729Z", "gap": "+100DAY" }] } “` An example query for **search highlighting** could look like this: “`JSON { "query": { "query": "description:workflow", "userQuery":"workflow" }, "highlight": { "prefix": "¿", "postfix": "?", "mergeContiguous": true, "fields": [ { "field": "cm:title" }, { "field": "description", "prefix": "(", "postfix": ")" } ] } } “` The example above changes the highlighting prefix and postfix from the default <em> for all fields to ¿? and just for the "description" field to (). The hightlight information is added in each node entry response; here is an example partial response: “` "entry": { "createdAt": "2016-10-12T15:24:31.202+0000", "isFolder": true, "search": { "score": 1, "highlight": [ { "field": "cm:title", "snippets": [ "Customized ¿Workflow? Process Definitions" ] }, { "field": "description", "snippets": [ "Customized (Workflow) Process Definitions" ] } ] }, “`
28 29 30 31 |
# File 'lib/alfresco/api/search_api.rb', line 28 def search(query_body, opts = {}) data, _status_code, _headers = search_with_http_info(query_body, opts) return data end |
#search_with_http_info(query_body, opts = {}) ⇒ Array<(ResultSetPaging, Fixnum, Hash)>
Searches Alfresco Note: this endpoint is available in Alfresco 5.2 and newer versions. **You specify all the parameters in this API in a JSON body**, URL parameters are not supported. A basic query looks like this: ```JSON { "query": { "query": "foo" } } ``` Note: These are the minimum possible query parameters. The default search language is afts ([Alfresco Full Text Search](docs.alfresco.com/5.1/concepts/rm-searchsyntax-intro.html)), but you can also specify cmis, and lucene. A basic CMIS query looks like this: ```JSON { "query": { "query": "select * from cmis:folder", "language": "cmis" } } ``` By default, **results are limited to the first 100.** Results can be restricted using "paging". For example: ```JSON "paging": { "maxItems": "50", "skipCount": "28" } ``` This example would ensure that results are **limited by Final Size**, skipping the first 28 results and returning the next 50. Alternatively, you can limit the results by using the **limits JSON body parameter**. For example, ```JSON "limits": { "permissionEvaluationTime": 20000, "permissionEvaluationCount": 2000 } ``` You can use the **include JSON body parameter** to return additional information. This works in the same way as in the /nodes/nodeId/children method in the core API. For example: ```JSON "include": ["aspectNames", "properties", "isLink"] ``` You can use the **fields JSON body parameter** to restrict the fields returned within a response if, for example, you want to save on overall bandwidth. This works in the same way as in the /nodes/nodeId/children method in the core API. For example: ```JSON "fields": ["id", "name", "search"] ``` You can sort the results using the **sort JSON body parameter**, for example: ```JSON "sort": ["field":"cm:description", "ascending":"true"] ``` Note: the sort parameter is not supported for CMIS queries. By default, search uses the **"nodes" location**, which is the **content store known as workspace://SpacesStore**. To change the scope to another location you can use the **locations JSON body parameter**. You can specify either nodes (the default), versions or deleted-nodes. For example, ```JSON "scope": { "locations": ["deleted-nodes"] } ``` You can specify templates using the **templates JSON body parameter**, for example: ```JSON "templates": ["_PERSON","template": "|%firstName OR |%lastName OR |%userName", "mytemplate","template": "%cm:content"] ``` **Note: Spell checking only works on Search Services (Solr 6) if you have already enabled suggestions.** For **spell checking** you can use a query like this: ```JSON { "query": { "query": "cm:title:alfrezco" }, "spellcheck": "alfrezco" } ``` If you are already specifying "userQuery" then the following may be easier and produces the same result : ```JSON { "query": { "query": "cm:title:alfrezco", "userQuery": "alfrezco" }, "spellcheck": {} } ``` The spellcheck response includes a spellCheck context like this: ```JSON "context": { "spellCheck": { "type": "searchInsteadFor", "suggestions": ["alfresco"] } }, ``` To specify defaults, you use a **defaults JSON body parameter**, for example: ```JSON "defaults": { "textAttributes": [ "cm:content", "cm:name" ], "defaultFTSOperator": "AND", "defaultFTSFieldOperator": "OR", "namespace": "cm", "defaultFieldName": "PATH" } ``` You can specify several filter queries using the **filterQueries JSON body parameter**, for example: ```JSON "filterQueries": ["TYPE:'cm:folder'","cm:creator:mjackson"] ``` You can specify several facet queries using the **facetQueries JSON body parameter**, for example: ```JSON "facetQueries": ["created:2016","label": "CreatedThisYear"] ``` The response will contain a matching "context" section, the "label" will match the facet query. ```JSON "context": { "facetQueries": [ "CreatedThisYear","count": 3 ] }, ``` A complete query for facetting via the content.size field looks this: ```JSON { "query": { "query": "presentation", "language": "afts" }, "facetQueries": [ "content.size:[0 TO 10240]", "label": "xtra small", "content.size:[10240 TO 102400]", "label": "small", "content.size:[102400 TO 1048576]", "label": "medium", "content.size:[1048576 TO 16777216]", "label": "large", "content.size:[16777216 TO 134217728]", "label": "xtra large", "content.size:[134217728 TO MAX]", "label": "XX large" ], "facetFields": [{"field": "'content.size'"]} } ``` The response will contain a matching "context" section, the "label" will match the facet query. ```JSON "context": { "facetQueries": [ { "label": "small","count": 2 }, { "label": "large","count": 0 }, { "label": "xtra small","count": 5 }, { "label": "xtra large","count": 56}, { "label": "medium","count": 4 }, { "label": "XX large", "count": 1 } ] }, ``` You can specify several facet fields using the **facetFields JSON body parameter**, for example: ```JSON "facetFields": [{"field": "creator", "mincount": 1, "modifier", "mincount": 1]} ``` The response will contain a matching "context" section, the "label" will match the facet field. ```JSON "context": { "facetsFields": [ { "label": "creator", "buckets": [ { "label": "System", "count": 75 }, { "label": "mjackson", "count": 5 } ]}, { "label": "modifier", "buckets": [ { "label": "System", "count": 72 }, { "label": "mjackson", "count": 5 }, { "label": "admin", "count": 3 } ]} ] }, ``` Grouping facet queries that go together can be done by specifying the group label in the fact queries as follow: ```JSON { "query": { "query": "presentation" }, "facetQueries": [ "content.size:[0 TO 102400]", "label": "small", "group":"foo", "content.size:[102400 TO 1048576]", "label": "medium","group":"foo", "content.size:[1048576 TO 16777216]", "label": "large","group":"foo" ] } ``` The above query returns the results a faceted field grouped under the label foo: ```JSON { "context": {"facetsFields": [{ "label": "foo", "buckets": [ { "count": 109, "label": "small", "filterQuery": "content.size:[0 TO 102400]" }, { "count": 0, "label": "large", "filterQuery": "content.size:[1048576 TO 16777216]" }, { "count": 0, "label": "medium", "filterQuery": "content.size:[102400 TO 1048576]" } ] }] } ``` Range Faceting is supported by the **ranges JSON body parameter**, for example: ```JSON { "query": { "query": "presentation" }, "ranges": [ { "field": "content.size", "start": "0", "end": "100", "gap": "20", "hardend": true }, { "field": "created", "start": "2015-09-29T10:45:15.729Z", "end": "2016-09-29T10:45:15.729Z", "gap": "+100DAY" }] } ``` An example query for **search highlighting** could look like this: ```JSON { "query": { "query": "description:workflow", "userQuery":"workflow" }, "highlight": { "prefix": "¿", "postfix": "?", "mergeContiguous": true, "fields": [ { "field": "cm:title" }, { "field": "description", "prefix": "(", "postfix": ")" } ] } } ``` The example above changes the highlighting prefix and postfix from the default <em> for all fields to ¿? and just for the "description" field to (). The hightlight information is added in each node entry response; here is an example partial response: ``` "entry": { "createdAt": "2016-10-12T15:24:31.202+0000", "isFolder": true, "search": { "score": 1, "highlight": [ { "field": "cm:title", "snippets": [ "Customized ¿Workflow? Process Definitions" ] }, { "field": "description", "snippets": [ "Customized (Workflow) Process Definitions" ] } ] }, ```
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/alfresco/api/search_api.rb', line 38 def search_with_http_info(query_body, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug "Calling API: SearchApi.search ..." end # verify the required parameter 'query_body' is set if @api_client.config.client_side_validation && query_body.nil? fail ArgumentError, "Missing the required parameter 'query_body' when calling SearchApi.search" end # resource path local_var_path = "/search" # query parameters query_params = {} # header parameters header_params = {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # HTTP header 'Content-Type' header_params['Content-Type'] = @api_client.select_header_content_type(['application/json']) # form parameters form_params = {} # http body (model) post_body = @api_client.object_to_http_body(query_body) auth_names = ['basicAuth'] data, status_code, headers = @api_client.call_api(:POST, local_var_path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => 'ResultSetPaging') if @api_client.config.debugging @api_client.config.logger.debug "API called: SearchApi#search\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end |