class Alfresco::SearchApi

Attributes

api_client[RW]

Public Class Methods

new(api_client = ApiClient.default) click to toggle source
# File lib/alfresco/api/search_api.rb, line 19
def initialize(api_client = ApiClient.default)
  @api_client = api_client
end

Public Instance Methods

search_with_http_info(query_body, opts = {}) click to toggle source

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 { "query&quot;: { "query&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 { "query&quot;: { "query&quot;: "select * from cmis:folder&quot;, "language&quot;: "cmis&quot; } } &#x60;&#x60;&#x60; By default, **results are limited to the first 100.** Results can be restricted using "paging&quot;. For example: &#x60;&#x60;&#x60;JSON "paging&quot;: { "maxItems&quot;: "50&quot;, "skipCount&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 "limits&quot;: { "permissionEvaluationTime&quot;: 20000, "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 "include&quot;: [&quot;aspectNames&quot;, "properties&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 "fields&quot;: [&quot;id&quot;, "name&quot;, "search&quot;] &#x60;&#x60;&#x60; You can sort the results using the **sort JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON "sort&quot;: [{&quot;type&quot;:&quot;FIELD&quot;, "field&quot;:&quot;cm:description&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 "scope&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 "templates&quot;: [{&quot;name&quot;: "_PERSON&quot;,&quot;template&quot;: "|%firstName OR |%lastName OR |%userName&quot;}, {&quot;name&quot;: "mytemplate&quot;,&quot;template&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 { "query&quot;: { "query&quot;: "cm:title:alfrezco&quot; }, "spellcheck&quot;: {&quot;query&quot;: "alfrezco&quot;} } &#x60;&#x60;&#x60; If you are already specifying "userQuery&quot; then the following may be easier and produces the same result : &#x60;&#x60;&#x60;JSON { "query&quot;: { "query&quot;: "cm:title:alfrezco&quot;, "userQuery&quot;: "alfrezco&quot; }, "spellcheck&quot;: {} } &#x60;&#x60;&#x60; The spellcheck response includes a spellCheck context like this: &#x60;&#x60;&#x60;JSON "context&quot;: { "spellCheck&quot;: { "type&quot;: "searchInsteadFor&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 "defaults&quot;: { "textAttributes&quot;: [ "cm:content&quot;, "cm:name&quot; ], "defaultFTSOperator&quot;: "AND&quot;, "defaultFTSFieldOperator&quot;: "OR&quot;, "namespace&quot;: "cm&quot;, "defaultFieldName&quot;: "PATH&quot; } &#x60;&#x60;&#x60; You can specify several filter queries using the **filterQueries JSON body parameter**, for example: &#x60;&#x60;&#x60;JSON "filterQueries&quot;: [{&quot;query&quot;: "TYPE:&#39;cm:folder&#39;&quot;},{&quot;query&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 "facetQueries&quot;: [{&quot;query&quot;: "created:2016&quot;,&quot;label&quot;: "CreatedThisYear&quot;}] &#x60;&#x60;&#x60; The response will contain a matching "context&quot; section, the "label&quot; will match the facet query. &#x60;&#x60;&#x60;JSON "context&quot;: { "facetQueries&quot;: [ {&quot;label&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 { "query&quot;: { "query&quot;: "presentation&quot;, "language&quot;: "afts&quot; }, "facetQueries&quot;: [ {&quot;query&quot;: "content.size:[0 TO 10240]&quot;, "label&quot;: "xtra small&quot;}, {&quot;query&quot;: "content.size:[10240 TO 102400]&quot;, "label&quot;: "small&quot;}, {&quot;query&quot;: "content.size:[102400 TO 1048576]&quot;, "label&quot;: "medium&quot;}, {&quot;query&quot;: "content.size:[1048576 TO 16777216]&quot;, "label&quot;: "large&quot;}, {&quot;query&quot;: "content.size:[16777216 TO 134217728]&quot;, "label&quot;: "xtra large&quot;}, {&quot;query&quot;: "content.size:[134217728 TO MAX]&quot;, "label&quot;: "XX large&quot;} ], "facetFields&quot;: {&quot;facets&quot;: [{&quot;field&quot;: "&#39;content.size&#39;&quot;}]} } &#x60;&#x60;&#x60; The response will contain a matching "context&quot; section, the "label&quot; will match the facet query. &#x60;&#x60;&#x60;JSON "context&quot;: { "facetQueries&quot;: [ { "label&quot;: "small&quot;,&quot;count&quot;: 2 }, { "label&quot;: "large&quot;,&quot;count&quot;: 0 }, { "label&quot;: "xtra small&quot;,&quot;count&quot;: 5 }, { "label&quot;: "xtra large&quot;,&quot;count&quot;: 56}, { "label&quot;: "medium&quot;,&quot;count&quot;: 4 }, { "label&quot;: "XX large&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 "facetFields&quot;: {&quot;facets&quot;: [{&quot;field&quot;: "creator&quot;, "mincount&quot;: 1}, {&quot;field&quot;: "modifier&quot;, "mincount&quot;: 1}]} &#x60;&#x60;&#x60; The response will contain a matching "context&quot; section, the "label&quot; will match the facet field. &#x60;&#x60;&#x60;JSON "context&quot;: { "facetsFields&quot;: [ { "label&quot;: "creator&quot;, "buckets&quot;: [ { "label&quot;: "System&quot;, "count&quot;: 75 }, { "label&quot;: "mjackson&quot;, "count&quot;: 5 } ]}, { "label&quot;: "modifier&quot;, "buckets&quot;: [ { "label&quot;: "System&quot;, "count&quot;: 72 }, { "label&quot;: "mjackson&quot;, "count&quot;: 5 }, { "label&quot;: "admin&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 { "query&quot;: { "query&quot;: "presentation&quot; }, "facetQueries&quot;: [ {&quot;query&quot;: "content.size:[0 TO 102400]&quot;, "label&quot;: "small&quot;, "group&quot;:&quot;foo&quot;}, {&quot;query&quot;: "content.size:[102400 TO 1048576]&quot;, "label&quot;: "medium&quot;,&quot;group&quot;:&quot;foo&quot;}, {&quot;query&quot;: "content.size:[1048576 TO 16777216]&quot;, "label&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 { "context&quot;: {&quot;facetsFields&quot;: [{ "label&quot;: "foo&quot;, "buckets&quot;: [ { "count&quot;: 109, "label&quot;: "small&quot;, "filterQuery&quot;: "content.size:[0 TO 102400]&quot; }, { "count&quot;: 0, "label&quot;: "large&quot;, "filterQuery&quot;: "content.size:[1048576 TO 16777216]&quot; }, { "count&quot;: 0, "label&quot;: "medium&quot;, "filterQuery&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 { "query&quot;: { "query&quot;: "presentation&quot; }, "ranges&quot;: [ { "field&quot;: "content.size&quot;, "start&quot;: "0&quot;, "end&quot;: "100&quot;, "gap&quot;: "20&quot;, "hardend&quot;: true }, { "field&quot;: "created&quot;, "start&quot;: "2015-09-29T10:45:15.729Z&quot;, "end&quot;: "2016-09-29T10:45:15.729Z&quot;, "gap&quot;: "+100DAY&quot; }] } &#x60;&#x60;&#x60; An example query for **search highlighting** could look like this: &#x60;&#x60;&#x60;JSON { "query&quot;: { "query&quot;: "description:workflow&quot;, "userQuery&quot;:&quot;workflow&quot; }, "highlight&quot;: { "prefix&quot;: "¿&quot;, "postfix&quot;: "?&quot;, "mergeContiguous&quot;: true, "fields&quot;: [ { "field&quot;: "cm:title&quot; }, { "field&quot;: "description&quot;, "prefix&quot;: "(", "postfix&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 "description&quot; field to (). The hightlight information is added in each node entry response; here is an example partial response: &#x60;&#x60;&#x60; "entry&quot;: { "createdAt&quot;: "2016-10-12T15:24:31.202+0000&quot;, "isFolder&quot;: true, "search&quot;: { "score&quot;: 1, "highlight&quot;: [ { "field&quot;: "cm:title&quot;, "snippets&quot;: [ "Customized ¿Workflow? Process Definitions&quot; ] }, { "field&quot;: "description&quot;, "snippets&quot;: [ "Customized (Workflow) Process Definitions&quot; ] } ] }, &#x60;&#x60;&#x60; @param query_body Generic query API @param [Hash] opts the optional parameters @return [Array<(ResultSetPaging, Fixnum, Hash)>] ResultSetPaging data, response status code and response headers

# 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