Quickstart

Simple introduction to glitter.

1.Connection

Connect Glitter network using glitter_sdk package.

from glitter_sdk import GlitterClient
client = GlitterClient()

2.Data model

In the example below we create a schema which is used to describe data model. After creation success, you will be able to check the detail of the schema info here.

# Create a schema with a url and title.
schema = [
    {
        "name": "url",
        "type": "string",
        "primary": "true",
        "index": {
            "type": "keyword"
        }
    },
    {
        "name": "title",
        "type": "string",
        "index": {
            "type": "text"
        }
    }
]
res = client.db.create_schema("sample", schema)
# Get the schema you create.
client.db.get_schema("sample")

3.Put doc

Put_doc is used to insert a record into the schema you created earlier. Once success, you will be able to see the details of the transaction here.

put_res = client.db.put_doc("sample", {
        "url": "https://glitterprotocol.io/",
        "title": "A Decentralized Content Indexing Network",
    })

5. Other search examples

Below is a list of examples for searching data in rss.

# Standard query for performing a full-text search.
client.db.search(schema_name="rss", query_word="oppo")
# Search 'oppo' in the 'title' query_field.
client.db.search(schema_name="rss", query_word="oppo", query_field=['title'])
# Search 'Mobile' in the 'tags' query_field.
client.db.search(schema_name="rss", query_word="Mobile", query_field=['tags'])
# Aggregate search result by the "tags" field defined in the schema.
client.db.search(schema_name="rss", query_word="oppo", query_field=['title', 'description'], filters=[],
                 aggs_field=["tags"])