diff options
| author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-12-17 16:44:14 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-17 16:44:14 -0500 | 
| commit | 8e548a17eba180b5773a9900de3f3cb3a92ec6ff (patch) | |
| tree | a0aa76481432fd5c510c3769ccadade86c7f15fa /ext/js/display | |
| parent | 19ab9df6e4110ef7d5927c95993141a1f8960c53 (diff) | |
Dictionary database term source info (#2039)
* Update DictionaryDatabase._findMultiBulk's createResult callback signature
* Simplify _splitField use
* Update sequence
* Expose new fields 'matchType' and 'matchSource' as part of term data
* Expose matchType and matchSource as part of TermSource
* Update sourceTermExactMatchCount calculation
* Update test data
* Expose matchType and matchSource info in HTML attributes
* Add primaryMatchTypes attribute
Diffstat (limited to 'ext/js/display')
| -rw-r--r-- | ext/js/display/display-generator.js | 17 | 
1 files changed, 14 insertions, 3 deletions
| diff --git a/ext/js/display/display-generator.js b/ext/js/display/display-generator.js index fc377df1..409706c0 100644 --- a/ext/js/display/display-generator.js +++ b/ext/js/display/display-generator.js @@ -64,9 +64,14 @@ class DisplayGenerator {          const uniqueTerms = new Set();          const uniqueReadings = new Set(); -        for (const {term, reading} of headwords) { +        const primaryMatchTypes = new Set(); +        for (const {term, reading, sources} of headwords) {              uniqueTerms.add(term);              uniqueReadings.add(reading); +            for (const {matchType, isPrimary} of sources) { +                if (!isPrimary) { continue; } +                primaryMatchTypes.add(matchType); +            }          }          node.dataset.format = type; @@ -78,6 +83,7 @@ class DisplayGenerator {          node.dataset.uniqueReadingCount = `${uniqueReadings.size}`;          node.dataset.frequencyCount = `${frequencies.length}`;          node.dataset.groupedFrequencyCount = `${groupedFrequencies.length}`; +        node.dataset.primaryMatchTypes = [...primaryMatchTypes].join(' ');          for (let i = 0, ii = headwords.length; i < ii; ++i) {              const node2 = this._createTermHeadword(headwords[i], i, pronunciations); @@ -235,11 +241,14 @@ class DisplayGenerator {          const {term, reading, tags, sources} = headword;          let isPrimaryAny = false; -        for (const {isPrimary} of sources) { +        const matchTypes = new Set(); +        const matchSources = new Set(); +        for (const {matchType, matchSource, isPrimary} of sources) {              if (isPrimary) {                  isPrimaryAny = true; -                break;              } +            matchTypes.add(matchType); +            matchSources.add(matchSource);          }          const node = this._templates.instantiate('headword'); @@ -249,6 +258,8 @@ class DisplayGenerator {          node.dataset.isPrimary = `${isPrimaryAny}`;          node.dataset.readingIsSame = `${reading === term}`;          node.dataset.frequency = DictionaryDataUtil.getTermFrequency(tags); +        node.dataset.matchTypes = [...matchTypes].join(' '); +        node.dataset.matchSources = [...matchSources].join(' ');          const {wordClasses} = headword;          const pronunciationCategories = this._getPronunciationCategories(reading, pronunciations, wordClasses, headwordIndex); |