From 69948217d535962c2e149c2e56cccc9faf1c1b3d Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Dec 2020 15:17:04 +0100 Subject: [PATCH] search results implemented --- .../UI/Spaces/Docs-Space/DocsSpace.js | 246 ++++++++++++------ 1 file changed, 170 insertions(+), 76 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index a8297e32c..c753525e3 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -265,14 +265,15 @@ function newSuperalgosDocSpace() { for (let j = 0; j < PROJECTS_ARRAY.length; j++) { let project = PROJECTS_ARRAY[j] - let documentIndex + let documentIndex /* Search in Nodes */ for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.length; i++) { documentIndex = { phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. document: SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema[i], - documentType: 'Node' + documentType: 'Node', + project: project } indexDocument(documentIndex) docsIndex.push(documentIndex) @@ -282,7 +283,8 @@ function newSuperalgosDocSpace() { documentIndex = { phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. document: SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema[i], - documentType: 'Concept' + documentType: 'Concept', + project: project } indexDocument(documentIndex) docsIndex.push(documentIndex) @@ -292,7 +294,8 @@ function newSuperalgosDocSpace() { documentIndex = { phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. document: SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema[i], - documentType: 'Topics' + documentType: 'Topics', + project: project } indexDocument(documentIndex) docsIndex.push(documentIndex) @@ -644,106 +647,197 @@ function newSuperalgosDocSpace() { } function renderSearchResultsPage() { - let HTML = '' - // Logo & Search Box + let resultsArary = [] + buildResultsArray() + buildHTML() - HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '' - HTML = HTML + '
' - HTML = HTML + '
' + function buildResultsArray() { + for (let i = 0; i < docsIndex.length; i++) { + let documentIndex = docsIndex[i] + let documentPoints = 0 - // Tabs + for (const style in documentIndex.phraseCount) { + let thisPhraseCount = documentIndex.phraseCount[style].get(searchPhrase.toLowerCase()) + if (thisPhraseCount === undefined) { + thisPhraseCount = 0 + } + switch (style) { + case 'definition': { + documentPoints = documentPoints + thisPhraseCount * 9 + break + } + case 'title': { + documentPoints = documentPoints + thisPhraseCount * 10 + break + } + case 'subtitle': { + documentPoints = documentPoints + thisPhraseCount * 8 + break + } + case 'text': { + documentPoints = documentPoints + thisPhraseCount * 2 + break + } + case 'list': { + documentPoints = documentPoints + thisPhraseCount * 2 + break + } + case 'note': { + documentPoints = documentPoints + thisPhraseCount * 4 + break + } + case 'warning': { + documentPoints = documentPoints + thisPhraseCount * 6 + break + } + case 'important': { + documentPoints = documentPoints + thisPhraseCount * 7 + break + } + case 'success': { + documentPoints = documentPoints + thisPhraseCount * 5 + break + } + case 'callout': { + documentPoints = documentPoints + thisPhraseCount * 5 + break + } + case 'summary': { + documentPoints = documentPoints + thisPhraseCount * 6 + break + } + case 'json': { + documentPoints = documentPoints + thisPhraseCount * 2 + break + } + case 'javascript': { + documentPoints = documentPoints + thisPhraseCount * 2 + break + } + case 'gif': { + documentPoints = documentPoints + thisPhraseCount * 1 + break + } + case 'png': { + documentPoints = documentPoints + thisPhraseCount * 1 + break + } + } + } - HTML = HTML + '
' - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' - HTML = HTML + '' + if (documentPoints === 0) { continue } // No matches anywhere - // Results + let result = { + documentIndex: documentIndex, + documentPoints: documentPoints + } + let added = false - HTML = HTML + '
' + if (resultsArary.length === 0) { + resultsArary.push(result) + added = true + } else { + for (let j = 0; j < resultsArary.length; j++) { + let thisResult = resultsArary[j] + if (result.documentPoints > thisResult.documentPoints) { + resultsArary.splice(j, 0, result) + added = true + break + } + } + } + if (added === false) { + resultsArary.push(result) + } + } + } - // All Tab + function buildHTML() { + let HTML = '' - HTML = HTML + '
' + // Logo & Search Box + HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '' + HTML = HTML + '
' + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '

Superalgos > Node

' - HTML = HTML + '

Data Storage

' - HTML = HTML + '

The data storage node holds the definitions as to what data is stored in the corresponding network node.

' - HTML = HTML + '
' + // Tabs + HTML = HTML + '
' + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' + HTML = HTML + '' - HTML = HTML + '
' - HTML = HTML + '

Superalgos > Node

' - HTML = HTML + '

Data Mines Data

' - HTML = HTML + '

Session independent data refers to data generated by sensors and indicators, not related to trading sessions.

' - HTML = HTML + '
' + // Results + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '

Superalgos > Node

' - HTML = HTML + '

Trading Mines Data

' - HTML = HTML + '

Session-based data refers to data that is generated as a consequence of running a trading session, that is, data the trading bot instance generates while running backtesting, paper trading, forward testing, or live trading sessions.

' - HTML = HTML + '
' + // All Tab + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '

Ethereum > Topic

' - HTML = HTML + '

Blockchain Data Mining

' - HTML = HTML + '

Mining data from the Ethereum blockchain requires running an Ethereum node. Superalgos interfaces with the Ethereum blockchaing via...

' - HTML = HTML + '
' + for (let i = 0; i < resultsArary.length; i++) { + let result = resultsArary[i] - HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '

' + result.documentIndex.project + ' > ' + result.documentIndex.documentType + '

' + HTML = HTML + '

' + result.documentIndex.document.type + '

' + HTML = HTML + '

' + result.documentIndex.document.definition + '

' + HTML = HTML + '
' + } - // Nodes Tab + HTML = HTML + '
' - HTML = HTML + '
' + // Nodes Tab + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '

Superalgos > Node

' - HTML = HTML + '

Data Storage

' - HTML = HTML + '

The data storage node holds the definitions as to what data is stored in the corresponding network node.

' - HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '

Superalgos > Node

' + HTML = HTML + '

Data Storage

' + HTML = HTML + '

The data storage node holds the definitions as to what data is stored in the corresponding network node.

' + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '

Superalgos > Node

' - HTML = HTML + '

Data Mines Data

' - HTML = HTML + '

Session independent data refers to data generated by sensors and indicators, not related to trading sessions.

' - HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '

Superalgos > Node

' + HTML = HTML + '

Data Mines Data

' + HTML = HTML + '

Session independent data refers to data generated by sensors and indicators, not related to trading sessions.

' + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '

Superalgos > Node

' - HTML = HTML + '

Trading Mines Data

' - HTML = HTML + '

Session-based data refers to data that is generated as a consequence of running a trading session, that is, data the trading bot instance generates while running backtesting, paper trading, forward testing, or live trading sessions.

' - HTML = HTML + '
' + HTML = HTML + '
' + HTML = HTML + '

Superalgos > Node

' + HTML = HTML + '

Trading Mines Data

' + HTML = HTML + '

Session-based data refers to data that is generated as a consequence of running a trading session, that is, data the trading bot instance generates while running backtesting, paper trading, forward testing, or live trading sessions.

' + HTML = HTML + '
' - HTML = HTML + '
' + HTML = HTML + '
' - // End Content + // End Content + HTML = HTML + '
' + HTML = HTML + '
' - HTML = HTML + '
' - HTML = HTML + '
' + // End Section + HTML = HTML + '
' - // End Section - - HTML = HTML + '' - - let docsSpaceDiv = document.getElementById('docs-space-div') - docsSpaceDiv.innerHTML = HTML + addFooter() - detectEnterOnSearchBox() + let docsSpaceDiv = document.getElementById('docs-space-div') + docsSpaceDiv.innerHTML = HTML + addFooter() + detectEnterOnSearchBox() + } } function detectEnterOnSearchBox() { const element = document.getElementsByClassName("docs-search-input")[0] + if (searchPhrase !== undefined) { + element.value = searchPhrase + } + element.focus() element.addEventListener("keyup", function (event) { if (event.key === "Enter" || event.keyCode === 13) { - let searchPhrase = element.value + searchPhrase = element.value renderSearchResultsPage() } });