Skip to content

Commit

Permalink
feat(query): add schemas and config class for index and query configs
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Dec 19, 2019
1 parent e0c5516 commit ece8df4
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/IndexConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const SchemaDerivedConfig = require('./SchemaDerivedConfig.js');
const NamedMapProxy = require('./NamedMapProxy');

class IndexConfig extends SchemaDerivedConfig {
constructor() {
super({
filename: 'helix-query.yaml',
rootschema: 'queryconfig.schema.json',
itemschema: 'index.schema.json',
proxy: NamedMapProxy,
rootprop: 'indices',
});
}
}

module.exports = IndexConfig;
46 changes: 46 additions & 0 deletions src/schemas/index.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"meta:license": [
"Copyright 2019 Adobe. All rights reserved.",
"This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
"you may not use this file except in compliance with the License. You may obtain a copy",
"of the License at http://www.apache.org/licenses/LICENSE-2.0",
"",
"Unless required by applicable law or agreed to in writing, software distributed under",
"the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
"OF ANY KIND, either express or implied. See the License for the specific language",
"governing permissions and limitations under the License."
],
"$id": "https://ns.adobe.com/helix/shared/index",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Index",
"type": "object",
"properties": {
"source": {
"type": "string",
"enum": ["html", "markdown"],
"title": "Source",
"description": "The source representation to be used by the indexer to extract values"
},
"fetch": {
"type": "string",
"format": "uri-template",
"description": "The source document to retrieve values from. Known variables in the URI Template are: `repo`, `ref`, `owner`, `path`"
},
"properties": {
"type": "object",
"title": "Properties",
"description": "The properties to add to the index",
"additionalProperties": {
"$ref": "https://ns.adobe.com/helix/shared/property"
}
},
"queries": {
"type": "object",
"title": "Queries",
"description": "Named queries that can be executed against this index",
"additionalProperties": {
"$ref": "https://ns.adobe.com/helix/shared/query"
}
}
}
}
25 changes: 25 additions & 0 deletions src/schemas/indexconfig.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"meta:license": [
"Copyright 2019 Adobe. All rights reserved.",
"This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
"you may not use this file except in compliance with the License. You may obtain a copy",
"of the License at http://www.apache.org/licenses/LICENSE-2.0",
"",
"Unless required by applicable law or agreed to in writing, software distributed under",
"the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
"OF ANY KIND, either express or implied. See the License for the specific language",
"governing permissions and limitations under the License."
],
"$id": "https://ns.adobe.com/helix/shared/indexconfig",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Index Configuration",
"type": "object",
"properties": {
"indices": {
"type": "object",
"additionalProperties": {
"$ref": "https://ns.adobe.com/helix/shared/index"
}
}
}
}
33 changes: 33 additions & 0 deletions src/schemas/property.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"meta:license": [
"Copyright 2019 Adobe. All rights reserved.",
"This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
"you may not use this file except in compliance with the License. You may obtain a copy",
"of the License at http://www.apache.org/licenses/LICENSE-2.0",
"",
"Unless required by applicable law or agreed to in writing, software distributed under",
"the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
"OF ANY KIND, either express or implied. See the License for the specific language",
"governing permissions and limitations under the License."
],
"$id": "https://ns.adobe.com/helix/shared/property",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Property",
"description": "The property in an Index",
"type": "object",
"properties": {
"select": {
"type": "string",
"description": "A CSS selector expression that selects nodes in the HTML (DOM) or Markdown (MDAST) syntax tree"
},
"value": {
"type": "string",
"description": "A ES6 template literal expression that extracts the value(s) from the matching node(s) to be stored in the index"
},
"faceted": {
"type": "boolean",
"description": "Whether to enable faceted search on this property",
"default": false
}
}
}
48 changes: 48 additions & 0 deletions src/schemas/query.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"meta:license": [
"Copyright 2019 Adobe. All rights reserved.",
"This file is licensed to you under the Apache License, Version 2.0 (the \"License\");",
"you may not use this file except in compliance with the License. You may obtain a copy",
"of the License at http://www.apache.org/licenses/LICENSE-2.0",
"",
"Unless required by applicable law or agreed to in writing, software distributed under",
"the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS",
"OF ANY KIND, either express or implied. See the License for the specific language",
"governing permissions and limitations under the License."
],
"$id": "https://ns.adobe.com/helix/shared/property",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Query",
"description": "A named query that can be run against an index",
"type": "object",
"properties": {
"select": {
"query": "string",
"description": "The base query to run",
"default": "*"
},
"hitsPerPage": {
"type": "integer",
"minimum": 1,
"default": 25,
"description": "How many hits each page of search results should contain"
},
"cache": {
"type": "integer",
"description": "How long (in seconds) search results should be cached on the CDN",
"default": 0
},
"parameters": {
"type": "array",
"items": {
"type": "string",
"minLength": 1
},
"description": "Which URL parameters to accept in the query when served on the web"
},
"filters": {
"type": "string",
"description": "An ES6 template expression that determines which filters to apply"
}
}
}
41 changes: 41 additions & 0 deletions test/specs/queryconfigs/query.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 1
indices:
blog-posts:
source: html
fetch: https://${repo}-${owner}.project-helix.page/${path}
properties:
author:
select: main > div:nth-of-type(3) > p:nth-of-type(1)
value: |
${match('by (.*)')}
faceted: true
title:
select: h1:first-of-type
value: |
${textContent()}
date:
select: main > div:nth-of-type(3) > p:nth-of-type(2)
value: |
${parseTimestamp('[POSTED ON] MM-DD-YYYY')}
topics:
select: main > div:last-of-type > p:first-of-type
value: |
${match('(Topics: )? ([^,]+)')}
faceted: true
hero:
select: main > div > img:first-of-type
value: |
${attribute('src')}
queries:
all:
query: "*"
hitsPerPage: 25
cache: 10 minutes
by-author:
parameters:
- author
query: "*"
filters: |
author:${author}
cache: 5 minutes

0 comments on commit ece8df4

Please sign in to comment.