Chilkat Online Tools

SQL Server / MeiliSearch v0.24 / Update searchable attributes

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- This example assumes the Chilkat API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- [
    --   "title",
    --   "author"
    -- ]

    DECLARE @jarr int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonArray', @jarr OUT

    EXEC sp_OAMethod @jarr, 'AddStringAt', @success OUT, -1, 'title'
    EXEC sp_OAMethod @jarr, 'AddStringAt', @success OUT, -1, 'author'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'X-Meili-Api-Key', 'masterKey'

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @jarr, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', 'http://localhost:7700/indexes/indexUID/settings/searchable-attributes', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @jarr
        EXEC @hr = sp_OADestroy @sbRequestBody
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @jarr
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X POST
	-H "X-Meili-Api-Key: masterKey"
	-H "Content-Type: application/json"
	-d '["title", "author"]'
http://localhost:7700/indexes/indexUID/settings/searchable-attributes

Postman Collection Item JSON

{
  "name": "Update searchable attributes",
  "protocolProfileBehavior": {
    "disabledSystemHeaders": {
      "content-type": true
    }
  },
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "[\"title\", \"author\"]"
    },
    "url": {
      "raw": "{{url}}/indexes/{{indexUID}}/settings/searchable-attributes",
      "host": [
        "{{url}}"
      ],
      "path": [
        "indexes",
        "{{indexUID}}",
        "settings",
        "searchable-attributes"
      ]
    }
  },
  "response": [
  ]
}