-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(query): add schemas and config class for index and query configs
see adobe/helix-index-files#3 and #190
- Loading branch information
Showing
6 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|