Tutorial - Search | Chino.io

Introduction

The focus of this tutorial is to give a better explanation of our Search functionality.

After a brief explanation of all the Search functions, some practical examples will be provided.

This tutorial is available for the following programming languages: {{languages.join(", ")}}. In the setup you can change the programming language.

Search Documents

All the Search queries for Documents are made at the following url:

POST {{url}}/v1/search/documents/{{schema_id || '{schema_id}'}}

The list below details the parameters available for a Search request for Documents:

  • result_type - mandatory: it defines how the response is displayed. It can assume the following values:

    • FULL_CONTENT: this result returns the whole Document and also its content.

    • NO_CONTENT: same as above, except for the fact that the content is empty.

    • ONLY_ID: it returns only the IDs of the Documents that matched the Search.

    • COUNT: this query returns only the number of Documents that matched the Search.

  • filter_type - mandatory: it can be and or or based on the logic you want to apply to search parameters.

  • sort - optional: it is used to define the sorting of results.

  • filter - mandatory: it defines how the Search is carried out.

Search Users

All the Search queries for Users are made at the following url:

POST {{url}}/v1/search/users/{{user_schema_id || '{user_schema_id}'}}

Below there is a list of the available parameters for a Search request for Users and a short description of each one:

  • result_type - mandatory: it defines how the response is displayed. It can assume the following values:

    • FULL_CONTENT: same as for the Document Search.

    • COUNT: same as for the Document Search.

    • EXISTS: it returns a true if one or more Users matches the query, false otherwise.

    • USERNAME_EXISTS: it returns a true if the username already exists, false otherwise.

  • filter_type - mandatory: it can be and or or based on the logic you want to apply to search parameters.

  • sort - optional: it is used to define sorting of results.

  • filter - mandatory: it defines how the Search is made.

Filter options

Below there is a list of the available parameters for the filter_type option and a short description of each one:

  • eq - (=): equal, if the value is the same as the one specified.

  • lt - (<): less than.

  • lte - (<=): less than or equal.

  • gt - (>): greater than.

  • gte - (>=): greater than or equal.

  • is - (=): only for boolean.

  • in: if the value is contained in a list.

    An example of the usage of the in parameter is the following:

    The query will return all the Documents which has the integer field's value contained in the list.

Select language:

Register to Chino.io 

To register to our service go to consoleconsole, fill in the form, confirm the email and access.

Note: You can use Chino.io test environment for free.

Setup development environment

Install library

First thing to do is to setup an environment (optional) and install the SDK (mandatory)

(sudo) pip install git+https://github.com/chinoio/chino-python.git

Install library

First thing to do is to setup an environment (optional) and install the SDKs (mandatory)

There are two ways to install the SDKs:

If you're using Maven, then edit your project's pom.xml and add this:

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependency>
        <groupId>com.github.chinoio</groupId>
            <artifactId>chino-java</artifactId>
        <version>1.0</version>
    </dependency>

If you're using Gradle, then edit your project's build.gradle and add this:

    allprojects {
        repositories {
            ...
            maven {
                url 'https://jitpack.io'
            }
        }
    }

    dependencies {
        // ...
        compile 'com.github.chinoio:chino-java:1.0'
    }

The other method is building the SDKs from source:

git clone https://github.com/chinoio/chino-java.git
    cd chino-java
    ./gradlew build

The output will be in build/

And if you want a "fat jar" with all the dependencies inside use the following commands:

git clone https://github.com/chinoio/chino-java.git
    cd chino-java
    ./gradlew build shadowJar

In order to perform network operations your Android manifest must include the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Note:

Every function in android must be called in an AsynkTask to avoid the main Thread to stop!

You can use Postman to try our rest API. We provide a Collection, to be imported in Postman, which allows you to easily test every call in this tutorial.

You can download Postman at this link.

SDK distribution

You can integrate the CHINO.io Swift SDK into your project using one of several methods.

CocoaPods

To use CocoaPods, a dependency manager for Cocoa projects, you should first install it using the following command:

$ gem install cocoapods

Then navigate to the directory that contains your project and create a new file called Podfile. You can do this either with pod init, or open an existing Podfile, and then add

pod 'ChinoOSXLibrary', :git => 'https://github.com/chinoio/chino-ios.git', :tag => '1.0'

to the main loop. Your Podfile should look something like this:

use_frameworks!

target '<YOUR_PROJECT_NAME>' do
    pod 'ChinoOSXLibrary', :git => 'https://github.com/chinoio/chino-ios.git', :tag => '1.0'
end

Then, run the following command to install the dependency:

$ pod install

Once your project is integrated with the CHINO.io Swift SDK, you can pull SDK updates using the following command:

$ pod update

Write here your customer ID and Key

Here you can write your customerId and customerKey to have them filled out in the code. It's just for the purpose of the tutorial.

Note: if you use Postman all the calls to create the resources required are present in the Collection.

Click on the following button to add the Collection with the calls of this tutorial in Postman.
Postman will automatically set the values inserted in this page in the environment variables.

Note: if you want to add an environment in Postman, please fill the customer_id and customer_key in the box above.

Create a Repository

The next step is to create a Repository.

Repositories can be created via the API or via the console. For this first tutorial we create a Repository via the console.

We create a Repository using Postman

Note: without a Repository you can't create Schemas, and without Schemas you can't create Documents in which to store your data.

Once created we copy the (write here your repository_id) and we use it as constant in our code.

Create a Schema

The Schema represents the structure of the Document we want to store inside Chino. For this tutorial we store the following information:

  • patient_id : string - indexed the patient that we have visited

  • doctor_id : string - indexed a reference to a doctor that perform the visit

  • visit_type : string - indexed the type of the visit

  • visit : text - not indexed the response of the visit

  • date : datetime - indexed timestamp of when the visit was made

Note: if the field is indexed it can be used to search for Documents. Better explanations throughout this tutorial.

Note: this is the Schema over which we are going to grant Permissions.

We call this schema base_vist

Once created, copy the schema_id

Create a UserSchema

We create a UserSchema which defines the following attributes of the Users:

  • name: string - indexed the name of the user

  • last_name: string - indexed the last name of the user

  • date_birth: date - indexed the date of birth of the user

  • role: text - not indexed the role of the user (if patient or doctor)

Once created, copy here your user_schema_id:

Create a doctor

For this tutorial we use a simple case study: a doctor and two patients who share Documents using a Schema. We create the doctor and the patients under the same UserSchema.

Create patients

We create now the two patients under the same UserSchema.

First patient we create:

Once created, copy here the user_id of the first patient created:

Second patient we create:

Once created, copy here the user_id of the second patient created:

Create Documents

We create three Documents in order to apply the Search over some data.

First Document we create (we use the id of the first patient):

Second Document we create (we change the date):

Third Document we create (we change the id of the patient, the date and the visit type):