Skip to content

Instantly share code, notes, and snippets.

@lakhansamani
Last active June 9, 2021 12:01
Show Gist options
  • Save lakhansamani/117c05c44348312905c7ecc54dfa41af to your computer and use it in GitHub Desktop.
Save lakhansamani/117c05c44348312905c7ecc54dfa41af to your computer and use it in GitHub Desktop.
// Configure reactivesearch query schema
let jsonCode = [
'{',
' "query": [{\n\t}],',
' "settings": {}',
"}"
].join('\n');
let modelUri = monaco.Uri.parse("a://b/reactivesearch.json"); // a made up unique URI for our model
let model = monaco.editor.createModel(jsonCode, "json", modelUri);
const fields = ["name","name.search", "name.keyword", "address.search", "address.keyword"];
// configure the JSON language support with schemas and schema associations
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
validate: true,
schemas: [{
uri: "http://myserver/root-schema.json", // id of the first schema
fileMatch: [modelUri.toString()], // associate with our model
schema: {
type: "object",
properties: {
query: {
type: "array",
items: {
$ref: "http://myserver/query-schema.json"
}
},
settings: {
$ref: "http://myserver/settings-schema.json"
}
}
}
}, {
uri: "http://myserver/query-schema.json",
schema: {
type: "object",
required: ["id"],
properties: {
id: {
type: "string",
description: "Docs: https://docs.appbase.io/docs/search/reactivesearch-api/reference#id"
},
dataField: {
// make enum of searchable fields based on mappings
type: "array",
items: {
enum: fields
},
description: "Docs: https://docs.appbase.io/docs/search/reactivesearch-api/reference#dataField"
},
size: {
type: "number",
description: "Docs: https://docs.appbase.io/docs/search/reactivesearch-api/reference#size"
},
value: {
type: "string",
description: "Docs: https://docs.appbase.io/docs/search/reactivesearch-api/reference#value"
},
fieldWeight: {
type: "array",
items: {
type: "number"
},
description: "Docs: https://docs.appbase.io/docs/search/reactivesearch-api/reference#feidlWeight"
},
}
}
},
{
uri: "http://myserver/settings-schema.json",
schema: {
type: "object",
properties: {
recordAnalytics: {
type: "boolean",
}
}
}
}]
});
monaco.editor.create(document.getElementById("container"), {
model: model
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment