Class: Alfresco::SearchApi

Inherits:
Object
  • Object
show all
Defined in:
lib/alfresco/api/search_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client = ApiClient.default) ⇒ SearchApi

Returns a new instance of SearchApi.



19
20
21
# File 'lib/alfresco/api/search_api.rb', line 19

def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Instance Attribute Details

#api_clientObject

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" ] } ] }, “`

Parameters:

  • query_body

    Generic query API

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:



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: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;foo&quot; } } &#x60;&#x60;&#x60; 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: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;select * from cmis:folder&quot;, &quot;language&quot;: &quot;cmis&quot; } } &#x60;&#x60;&#x60; By default, **results are limited to the first 100.** Results can be restricted using &quot;paging&quot;. For example: &#x60;&#x60;&#x60;JSON &quot;paging&quot;: { &quot;maxItems&quot;: &quot;50&quot;, &quot;skipCount&quot;: &quot;28&quot; } &#x60;&#x60;&#x60; 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, &#x60;&#x60;&#x60;JSON &quot;limits&quot;: { &quot;permissionEvaluationTime&quot;: 20000, &quot;permissionEvaluationCount&quot;: 2000 } &#x60;&#x60;&#x60; 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: &#x60;&#x60;&#x60;JSON &quot;include&quot;: [&quot;aspectNames&quot;, &quot;properties&quot;, &quot;isLink&quot;] &#x60;&#x60;&#x60; 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: &#x60;&#x60;&#x60;JSON &quot;fields&quot;: [&quot;id&quot;, &quot;name&quot;, &quot;search&quot;] &#x60;&#x60;&#x60; You can sort the results using the **sort JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON &quot;sort&quot;: [&quot;field&quot;:&quot;cm:description&quot;, &quot;ascending&quot;:&quot;true&quot;] &#x60;&#x60;&#x60; Note: the sort parameter is not supported for CMIS queries. By default, search uses the **&quot;nodes&quot; 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, &#x60;&#x60;&#x60;JSON &quot;scope&quot;: { &quot;locations&quot;: [&quot;deleted-nodes&quot;] } &#x60;&#x60;&#x60; You can specify templates using the **templates JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON &quot;templates&quot;: [&quot;_PERSON&quot;,&quot;template&quot;: &quot;|%firstName OR |%lastName OR |%userName&quot;, &quot;mytemplate&quot;,&quot;template&quot;: &quot;%cm:content&quot;] &#x60;&#x60;&#x60; **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: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;cm:title:alfrezco&quot; }, &quot;spellcheck&quot;: &quot;alfrezco&quot; } &#x60;&#x60;&#x60; If you are already specifying &quot;userQuery&quot; then the following may be easier and produces the same result : &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;cm:title:alfrezco&quot;, &quot;userQuery&quot;: &quot;alfrezco&quot; }, &quot;spellcheck&quot;: {} } &#x60;&#x60;&#x60; The spellcheck response includes a spellCheck context like this: &#x60;&#x60;&#x60;JSON &quot;context&quot;: { &quot;spellCheck&quot;: { &quot;type&quot;: &quot;searchInsteadFor&quot;, &quot;suggestions&quot;: [&quot;alfresco&quot;] } }, &#x60;&#x60;&#x60; To specify defaults, you use a **defaults JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON &quot;defaults&quot;: { &quot;textAttributes&quot;: [ &quot;cm:content&quot;, &quot;cm:name&quot; ], &quot;defaultFTSOperator&quot;: &quot;AND&quot;, &quot;defaultFTSFieldOperator&quot;: &quot;OR&quot;, &quot;namespace&quot;: &quot;cm&quot;, &quot;defaultFieldName&quot;: &quot;PATH&quot; } &#x60;&#x60;&#x60; You can specify several filter queries using the **filterQueries JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON &quot;filterQueries&quot;: [&quot;TYPE:&#39;cm:folder&#39;&quot;,&quot;cm:creator:mjackson&quot;] &#x60;&#x60;&#x60; You can specify several facet queries using the **facetQueries JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON &quot;facetQueries&quot;: [&quot;created:2016&quot;,&quot;label&quot;: &quot;CreatedThisYear&quot;] &#x60;&#x60;&#x60; The response will contain a matching &quot;context&quot; section, the &quot;label&quot; will match the facet query. &#x60;&#x60;&#x60;JSON &quot;context&quot;: { &quot;facetQueries&quot;: [ &quot;CreatedThisYear&quot;,&quot;count&quot;: 3 ] }, &#x60;&#x60;&#x60; A complete query for facetting via the content.size field looks this: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;presentation&quot;, &quot;language&quot;: &quot;afts&quot; }, &quot;facetQueries&quot;: [ &quot;content.size:[0 TO 10240]&quot;, &quot;label&quot;: &quot;xtra small&quot;, &quot;content.size:[10240 TO 102400]&quot;, &quot;label&quot;: &quot;small&quot;, &quot;content.size:[102400 TO 1048576]&quot;, &quot;label&quot;: &quot;medium&quot;, &quot;content.size:[1048576 TO 16777216]&quot;, &quot;label&quot;: &quot;large&quot;, &quot;content.size:[16777216 TO 134217728]&quot;, &quot;label&quot;: &quot;xtra large&quot;, &quot;content.size:[134217728 TO MAX]&quot;, &quot;label&quot;: &quot;XX large&quot; ], &quot;facetFields&quot;: [{&quot;field&quot;: &quot;&#39;content.size&#39;&quot;]} } &#x60;&#x60;&#x60; The response will contain a matching &quot;context&quot; section, the &quot;label&quot; will match the facet query. &#x60;&#x60;&#x60;JSON &quot;context&quot;: { &quot;facetQueries&quot;: [ { &quot;label&quot;: &quot;small&quot;,&quot;count&quot;: 2 }, { &quot;label&quot;: &quot;large&quot;,&quot;count&quot;: 0 }, { &quot;label&quot;: &quot;xtra small&quot;,&quot;count&quot;: 5 }, { &quot;label&quot;: &quot;xtra large&quot;,&quot;count&quot;: 56}, { &quot;label&quot;: &quot;medium&quot;,&quot;count&quot;: 4 }, { &quot;label&quot;: &quot;XX large&quot;, &quot;count&quot;: 1 } ] }, &#x60;&#x60;&#x60; You can specify several facet fields using the **facetFields JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON &quot;facetFields&quot;: [{&quot;field&quot;: &quot;creator&quot;, &quot;mincount&quot;: 1, &quot;modifier&quot;, &quot;mincount&quot;: 1]} &#x60;&#x60;&#x60; The response will contain a matching &quot;context&quot; section, the &quot;label&quot; will match the facet field. &#x60;&#x60;&#x60;JSON &quot;context&quot;: { &quot;facetsFields&quot;: [ { &quot;label&quot;: &quot;creator&quot;, &quot;buckets&quot;: [ { &quot;label&quot;: &quot;System&quot;, &quot;count&quot;: 75 }, { &quot;label&quot;: &quot;mjackson&quot;, &quot;count&quot;: 5 } ]}, { &quot;label&quot;: &quot;modifier&quot;, &quot;buckets&quot;: [ { &quot;label&quot;: &quot;System&quot;, &quot;count&quot;: 72 }, { &quot;label&quot;: &quot;mjackson&quot;, &quot;count&quot;: 5 }, { &quot;label&quot;: &quot;admin&quot;, &quot;count&quot;: 3 } ]} ] }, &#x60;&#x60;&#x60; Grouping facet queries that go together can be done by specifying the group label in the fact queries as follow: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;presentation&quot; }, &quot;facetQueries&quot;: [ &quot;content.size:[0 TO 102400]&quot;, &quot;label&quot;: &quot;small&quot;, &quot;group&quot;:&quot;foo&quot;, &quot;content.size:[102400 TO 1048576]&quot;, &quot;label&quot;: &quot;medium&quot;,&quot;group&quot;:&quot;foo&quot;, &quot;content.size:[1048576 TO 16777216]&quot;, &quot;label&quot;: &quot;large&quot;,&quot;group&quot;:&quot;foo&quot; ] } &#x60;&#x60;&#x60; The above query returns the results a faceted field grouped under the label foo: &#x60;&#x60;&#x60;JSON { &quot;context&quot;: {&quot;facetsFields&quot;: [{ &quot;label&quot;: &quot;foo&quot;, &quot;buckets&quot;: [ { &quot;count&quot;: 109, &quot;label&quot;: &quot;small&quot;, &quot;filterQuery&quot;: &quot;content.size:[0 TO 102400]&quot; }, { &quot;count&quot;: 0, &quot;label&quot;: &quot;large&quot;, &quot;filterQuery&quot;: &quot;content.size:[1048576 TO 16777216]&quot; }, { &quot;count&quot;: 0, &quot;label&quot;: &quot;medium&quot;, &quot;filterQuery&quot;: &quot;content.size:[102400 TO 1048576]&quot; } ] }] } &#x60;&#x60;&#x60; Range Faceting is supported by the **ranges JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;presentation&quot; }, &quot;ranges&quot;: [ { &quot;field&quot;: &quot;content.size&quot;, &quot;start&quot;: &quot;0&quot;, &quot;end&quot;: &quot;100&quot;, &quot;gap&quot;: &quot;20&quot;, &quot;hardend&quot;: true }, { &quot;field&quot;: &quot;created&quot;, &quot;start&quot;: &quot;2015-09-29T10:45:15.729Z&quot;, &quot;end&quot;: &quot;2016-09-29T10:45:15.729Z&quot;, &quot;gap&quot;: &quot;+100DAY&quot; }] } &#x60;&#x60;&#x60; An example query for **search highlighting** could look like this: &#x60;&#x60;&#x60;JSON { &quot;query&quot;: { &quot;query&quot;: &quot;description:workflow&quot;, &quot;userQuery&quot;:&quot;workflow&quot; }, &quot;highlight&quot;: { &quot;prefix&quot;: &quot;¿&quot;, &quot;postfix&quot;: &quot;?&quot;, &quot;mergeContiguous&quot;: true, &quot;fields&quot;: [ { &quot;field&quot;: &quot;cm:title&quot; }, { &quot;field&quot;: &quot;description&quot;, &quot;prefix&quot;: &quot;(&quot;, &quot;postfix&quot;: &quot;)&quot; } ] } } &#x60;&#x60;&#x60; The example above changes the highlighting prefix and postfix from the default &lt;em&gt; for all fields to ¿? and just for the &quot;description&quot; field to (). The hightlight information is added in each node entry response; here is an example partial response: &#x60;&#x60;&#x60; &quot;entry&quot;: { &quot;createdAt&quot;: &quot;2016-10-12T15:24:31.202+0000&quot;, &quot;isFolder&quot;: true, &quot;search&quot;: { &quot;score&quot;: 1, &quot;highlight&quot;: [ { &quot;field&quot;: &quot;cm:title&quot;, &quot;snippets&quot;: [ &quot;Customized ¿Workflow? Process Definitions&quot; ] }, { &quot;field&quot;: &quot;description&quot;, &quot;snippets&quot;: [ &quot;Customized (Workflow) Process Definitions&quot; ] } ] }, &#x60;&#x60;&#x60;

Parameters:

  • query_body

    Generic query API

  • opts (Hash) (defaults to: {})

    the optional parameters

Returns:

  • (Array<(ResultSetPaging, Fixnum, Hash)>)

    ResultSetPaging data, response status code and response headers



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