1 stable release
3.0.1 | May 1, 2021 |
---|---|
3.0.0 |
|
2.1.2 |
|
1.1.5 |
|
0.0.3 |
|
#685 in HTTP server
51 downloads per month
34KB
571 lines
Portal - Full Text Search Web Service
Purpose
The purpose of this service is to be your full text search web service for any JSON client including JavaScript front-ends like React with fetch.
Portal is a competitor to ElasticSearch, MeiliSearch, AWS CloudSearch, AWS ElasticSearch Service, and Algolia.
Portal is built to be simple and blazing fast with JWT verification, indexing, deindexing, search, and word suggest.
Indexing is batch indexing by default.
To use this service you need to have a running sonic server and a broker server.
Features
- Very performant with almost no CPU and memory usage
- Supports full-text search and word suggestions in 87 natural languages
- Under 1000 lines of code
- Supports CORS
- Supports JWT authentication
- Supports JWT caching with expiry checking to minimize verify API calls
- Multi-tenant
- Supports SSL - full end-to-end encryption
- JSON API
- Auto-provision and renews SSL cert via LetsEncrypt or use your own SSL cert
- Uses user authorization scoping
- Built on sonic and broker
Use
- create a user on broker with the following scopes - for full permissions
portal:full
or granular permissionsportal:create_bucket, portal:delete_bucket, portal:index, portal:deindex, portal:search, or portal:suggest
- login to broker and get a JWT
- attach the JWT as an Authorization: Bearer {token} to the following JSON API endpoints
- create a bucket
Create Bucket
POST /create_bucket
- authenticated endpoint (Authorization: Bearer {jwt}) example:
{
"collection": "coffee",
"name": "tenant_1"
}
will return: 200
or 500
or 400
or 401
- note: bucket names must be globally unique
Delete Bucket
POST /delete_bucket
- authenticated endpoint (Authorization: Bearer {jwt}) example:
{
"collection": "coffee",
"name": "tenant_1"
}
will return: 200
or 500
or 400
or 401
Index
POST /index
- authenticated endpoint (Authorization: Bearer {jwt}) example:
{
"items": [{
"collection": "coffee",
"bucket": "tenant_1",
"id": "49e28aae-88d4-4c19-86d8-51f2c9f11039",
"data": {
"name": "roasted",
"image": "https://img.com/bucket/123/123.jpg"
},
"locale": "eng",
"indexes": ["name"]
}]
}
will return: 200
or 500
or 400
or 401
-
note: only buckets the user has created can be used in the index call
-
note:
locale
is an optional field of an ISO 639-3 locale code - if not defined the locale will be auto-detected -
Supported Locales:
- afr => Afrikaans
- aka => Akan
- amh => Amharic
- ara => Arabic
- azj => Azerbaijani (North)
- bel => Belarusian
- ben => Bengali
- bho => Bhojpuri
- bul => Bulgarian
- cat => Catalan, Valencian
- ceb => Cebuano
- ces => Czech
- cmn => Mandarin Chinese
- dan => Danish
- deu => German
- ell => Greek (Modern)
- eng => English
- epo => Esperanto
- est => Estonian
- fin => Finnish
- fra => French
- guj => Gujarati
- hat => Haitian, Haitian Creole
- hau => Hausa
- heb => Hebrew
- hin => Hindi
- hrv => Croatian
- hun => Hungarian
- ibo => Igbo
- ilo => Iloko
- ind => Indonesian
- ita => Italian
- jav => Javanese
- jpn => Japanese
- kan => Kannada
- kat => Georgian
- khm => Khmer, Central Khmer
- kin => Kinyarwanda
- kor => Korean
- kur => Kurdish
- lat => Latin
- lav => Latvian
- lit => Lithuanian
- mai => Maithili
- mal => Malayalam
- mar => Marathi
- mkd => Macedonian
- mlg => Malagasy
- mya => Burmese
- nep => Nepali (macrolanguage)
- nld => Dutch, Flemish
- nno => Norwegian Nynorsk
- nob => Norwegian Bokmål
- nya => Chewa, Chichewa, Nyanja
- ori => Oriya (macrolanguage)
- orm => Oromo
- pan => Panjabi, Punjabi
- pes => Iranian Persian
- pol => Polish
- por => Portuguese
- ron => Moldavian, Moldovan, Romanian
- run => Rundi
- rus => Russian
- sin => Sinhala, Sinhalese
- skr => Saraiki, Seraiki
- slk => Slovak
- slv => Slovenian
- sna => Shona
- som => Somali
- spa => Castilian, Spanish
- srp => Serbian
- swe => Swedish
- tam => Tamil
- tel => Telugu
- tgl => Tagalog
- tha => Thai
- tir => Tigrinya
- tuk => Turkmen
- tur => Turkish
- uig => Uighur, Uyghur
- ukr => Ukrainian
- urd => Urdu
- uzb => Uzbek
- vie => Vietnamese
- ydd => Eastern Yiddish
- yor => Yoruba
- zul => Zulu
Search
POST /search
- authenticated endpoint (Authorization: Bearer {jwt})
{
"collection": "coffee",
"bucket": "tenant_1",
"query": "roasted",
"limit": 10,
"offset": 10
}
limit
andoffset
are optional fields
will return: 200
or 500
or 400
or 401
200 - will return an array of objects
[
{
"collection": "coffee",
"bucket": "tenant_1",
"id": "49e28aae-88d4-4c19-86d8-51f2c9f11039",
"data": {
"name": "roasted",
"image": "https://img.com/bucket/123/123.jpg"
},
"locale": "eng",
"indexes": ["name"]
}
]
Word Suggest
POST /suggest
- authenticated endpoint (Authorization: Bearer {jwt})
{
"collection": "coffee",
"bucket": "tenant_1",
"query": "r",
"limit": 10
}
- note: limit is an optional field
will return: 200
or 500
or 400
or 401
{
"suggestions": ["roasted"]
}
Deindex
POST /deindex
- authenticated endpoint (Authorization: Bearer {jwt})
{
"ids": ["49e28aae-88d4-4c19-86d8-51f2c9f11039"]
}
will return: 200
or 500
or 400
or 401
Health Check
GET or HEAD /
- public endpoint
will return: 200
Install
cargo install portal
- the
origin
can be passed in as a flag - default*
- the
port
can be passed in as a flag - default8888
- can only be set for unsecure connections - the
secure
flag for https can be true or false - defaultfalse
- the
auto_cert
flag for an autorenewing LetsEncrypt SSL cert can be true or false - requires a resolvable domain - defaulttrue
- the
key_path
flag whenauto_cert
isfalse
to set the SSL key path for your own cert - defaultcerts/private_key.pem
- the
cert_path
flag whenauto_cert
isfalse
to set the SSL cert path for your own cert - defaultcerts/chain.pem
- the
certs
flag is the storage path of LetsEncrypt certs - defaultcerts
- the
db
flag is the path where the embedded database will be saved - defaultdb
- the
domain
flag is the domain name (e.g. api.broker.com) of the domain you want to register with LetsEncrypt - must be fully resolvable - the
sonic_server
flag is the sonic domain/ip/port of the sonic server - defaultlocalhost:1491
- the
sonic_password
flag is the sonic password set in the sonic config file - defaultSecretPassword
- the
broker
flag is the broker domain/ip/port of the broker server - defaulthttp://localhost:8080
- production example:
./portal --secure="true" --domain="index.broker.com" --sonic_server="sonic.broker.com" --sonic_password="wj34T%$Dx" --broker="https://broker.broker.com"
Service
There is an example systemctl
service for Ubuntu called portal.service
in the code
TechStack
Inspiration
Dependencies
~52–70MB
~1.5M SLoC