Chilkat Online Tools

PureBasic / MeiliSearch v0.24 / Search in index

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    queryParams.i = CkJsonObject::ckCreate()
    If queryParams.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(queryParams,"q","prinec")

    CkHttp::ckSetRequestHeader(http,"X-Meili-Api-Key","masterKey")

    resp.i = CkHttp::ckQuickRequestParams(http,"GET","http://localhost:7700/indexes/indexUID/search",queryParams)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(queryParams)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(queryParams)


    ProcedureReturn
EndProcedure

Curl Command

curl -G -d "q=prinec"
	-H "X-Meili-Api-Key: masterKey"
http://localhost:7700/indexes/indexUID/search

Postman Collection Item JSON

{
  "name": "Search in index",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{url}}/indexes/{{indexUID}}/search?q=prinec",
      "host": [
        "{{url}}"
      ],
      "path": [
        "indexes",
        "{{indexUID}}",
        "search"
      ],
      "query": [
        {
          "key": "q",
          "value": "prinec"
        },
        {
          "key": "offset",
          "value": "0",
          "disabled": true
        },
        {
          "key": "limit",
          "value": "1",
          "disabled": true
        },
        {
          "key": "attributesToRetrieve",
          "value": "title,author",
          "disabled": true
        },
        {
          "key": "attributesToCrop",
          "value": "title",
          "disabled": true
        },
        {
          "key": "attributesToHighlight",
          "value": "*",
          "disabled": true
        },
        {
          "key": "cropLength",
          "value": "5",
          "disabled": true
        },
        {
          "key": "filter",
          "value": "genre=\"fantasy\"",
          "disabled": true
        },
        {
          "key": "matches",
          "value": "true",
          "disabled": true
        },
        {
          "key": "facetsDistribution",
          "value": "genre",
          "disabled": true
        },
        {
          "key": "sort",
          "value": "price",
          "disabled": true
        }
      ]
    }
  },
  "response": [
  ]
}