From 1eb277673d89bd91d38e38d30a5a97d6df75984b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 17 Dec 2020 19:06:21 +0100 Subject: [PATCH] Search Improved --- .../UI/Spaces/Docs-Space/DocsSpace.js | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js index 23ef78afa..fe9fd8ce5 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/DocsSpace.js @@ -346,6 +346,20 @@ function newSuperalgosDocSpace() { documentIndex.phraseCount[style] = stylePhraseCount } + text = text.replaceAll('. ', ' ') + text = text.replaceAll(', ', ' ') + text = text.replaceAll('- ', ' ') + text = text.replaceAll('/ ', ' ') + text = text.replaceAll('_ ', ' ') + text = text.replaceAll(': ', ' ') + text = text.replaceAll('; ', ' ') + text = text.replaceAll('( ', ' ') + text = text.replaceAll(') ', ' ') + text = text.replaceAll('{ ', ' ') + text = text.replaceAll('} ', ' ') + text = text.replaceAll('[ ', ' ') + text = text.replaceAll('] ', ' ') + text = text.replaceAll('.', ' ') text = text.replaceAll(',', ' ') text = text.replaceAll('-', ' ') @@ -376,10 +390,13 @@ function newSuperalgosDocSpace() { } else { phrase = phrase + ' ' + word } - let thisPhraseCount = stylePhraseCount.get(phrase) + let key = cleanTextForSearch(phrase) + + let thisPhraseCount = stylePhraseCount.get(key) if (thisPhraseCount === undefined) { thisPhraseCount = 0 } thisPhraseCount++ - stylePhraseCount.set(phrase, thisPhraseCount) + + stylePhraseCount.set(key, thisPhraseCount) } } } @@ -388,6 +405,17 @@ function newSuperalgosDocSpace() { } } + function cleanTextForSearch(text) { + let result = text + result = result.replaceAll(' ', '') + result = result.replaceAll('s', '') + result = result.replaceAll('ing', '') + result = result.replaceAll('ed', '') + result = result.replaceAll('y', '') + result = result.replaceAll('ies', '') + return result + } + function finalize() { canvas.eventHandler.stopListening(browserResizedEventSubscriptionId) thisObject.sidePanelTab.container.eventHandler.stopListening(openingEventSubscriptionId) @@ -666,11 +694,12 @@ function newSuperalgosDocSpace() { let documentPoints = 0 for (const style in documentIndex.phraseCount) { - let thisPhraseCount = documentIndex.phraseCount[style].get(searchPhrase.toLowerCase()) + let key = cleanTextForSearch(searchPhrase.toLowerCase()) + let thisPhraseCount = documentIndex.phraseCount[style].get(key) if (thisPhraseCount === undefined) { thisPhraseCount = 0 } - if (searchPhrase.toLowerCase() === documentIndex.document.type.toLowerCase()) { + if (key === cleanTextForSearch(documentIndex.document.type.toLowerCase())) { documentPoints = documentPoints + thisPhraseCount * 100 } @@ -804,7 +833,12 @@ function newSuperalgosDocSpace() { HTML = HTML + '
' HTML = HTML + '

' + result.documentIndex.project + ' > ' + result.documentIndex.documentCategory + '

' HTML = HTML + '

' + result.documentIndex.document.type + '

' - HTML = HTML + '

' + result.documentIndex.document.definition + '

' + + if (result.documentIndex.document.definition !== undefined) { + HTML = HTML + '

' + result.documentIndex.document.definition + '

' + } else { + HTML = HTML + '

' + 'No definition available.' + '

' + } HTML = HTML + '
' } HTML = HTML + ''