Skip to content

Commit f077dad

Browse files
committed
display match in author name when not in primary language (#1024)
1 parent 2890856 commit f077dad

File tree

4 files changed

+88
-46
lines changed

4 files changed

+88
-46
lines changed

src/components/App.js

+42-22
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ function pretty(str:string) {
753753
}
754754

755755

756-
export function getPropLabel(that, i, withSpan = true, withLang = false, useI18n = "", useI18n_count = 1, storage, defaultToRID = false) {
756+
export function getPropLabel(that, i, withSpan = true, withLang = false, useI18n = "", useI18n_count = 1, storage, defaultToRID = false, matchingLabels) {
757757

758758

759759
if(!that.props.dictionary) return
@@ -784,35 +784,55 @@ export function getPropLabel(that, i, withSpan = true, withLang = false, useI18n
784784

785785
}
786786

787+
let lang, foundMatch
788+
789+
if(labels && matchingLabels?.length) {
790+
//console.log("gpl:",i,labels,matchingLabels)
791+
for(const l of labels) {
792+
const tmp = getLangLabel(that,"",[l])
793+
for(const m of matchingLabels) {
794+
if(m.k === tmp.value) {
795+
label = m.value
796+
lang = m.lang
797+
foundMatch = true
798+
break ;
799+
}
800+
}
801+
if(foundMatch) break;
802+
}
803+
}
804+
787805
//console.log("labels:", labels, i)
788806

789-
let lang
790-
if(labels) {
791-
792-
if(!Array.isArray(labels)) labels = [ labels ]
793-
794-
// fix for "Author: False" in facets on /search?r=bdr:P1KG13161&t=Work
795-
let filteredLabels = labels.filter(l => l.lang != undefined || l.fromKey == skos+"prefLabel")
796-
if(!filteredLabels.length) filteredLabels = labels
797-
label = getLangLabel(that,"",filteredLabels,true)
807+
if(!foundMatch) {
798808

799-
//loggergen.log("label:",i,label,labels)
800-
801-
if(label) {
802-
if(label.lang) lang = label.lang
803-
else if(label["@language"]) lang = label["@language"]
804-
else if(label["xml:lang"]) lang = label["xml:lang"]
809+
if(labels) {
810+
811+
if(!Array.isArray(labels)) labels = [ labels ]
805812

806-
if(label.value) label = label.value
807-
else if(label["@value"]) label = label["@value"]
813+
// fix for "Author: False" in facets on /search?r=bdr:P1KG13161&t=Work
814+
let filteredLabels = labels.filter(l => l.lang != undefined || l.fromKey == skos+"prefLabel")
815+
if(!filteredLabels.length) filteredLabels = labels
816+
label = getLangLabel(that,"",filteredLabels,true)
817+
818+
//loggergen.log("label:",i,label,labels)
819+
820+
if(label) {
821+
if(label.lang) lang = label.lang
822+
else if(label["@language"]) lang = label["@language"]
823+
else if(label["xml:lang"]) lang = label["xml:lang"]
808824

825+
if(label.value) label = label.value
826+
else if(label["@value"]) label = label["@value"]
827+
828+
}
829+
} else {
830+
831+
label = that.pretty?that.pretty(i):pretty(i)
809832
}
810-
} else {
811-
812-
label = that.pretty?that.pretty(i):pretty(i)
813833
}
814834

815-
if(withSpan) return <span {...lang?{lang}:{}} class={label?.includes(" ") ? "hasSpace":""}>{label}</span>
835+
if(withSpan) return <span {...lang?{lang}:{}} class={label?.includes(" ") ? "hasSpace":""}>{foundMatch ? highlight(label) : label}</span>
816836
else if(!withLang) return label
817837
else return {value:label,lang}
818838
}

src/lib/searchkit/components/CustomHit.js

+39-22
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
109109
const hidden_if_no_match_and_not_locale_en = [ "summary" ]
110110

111111
if(hit) {
112-
for(const name of ["prefLabel", "altLabel", /*"authorName",*/ "publisherName", "publisherLocation", "summary", "authorshipStatement", "comment", "seriesName"]) {
112+
for(const name of ["prefLabel", "altLabel", "authorName", "publisherName", "publisherLocation", "summary", "authorshipStatement", "comment", "seriesName"]) {
113113
if(!labels[name]) labels[name] = []
114114
for(const k of Object.keys(hit)) {
115115
if(k.startsWith(name) && !k.endsWith("_res")) {
@@ -143,7 +143,7 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
143143
}
144144
const idx = withHL.indexOf(untagged)
145145
let start = "", end = ""
146-
console.log("wHL:",hit.objectID,k,c,h,idx,num)
146+
//console.log("wHL:",hit.objectID,k,c,h,idx,num)
147147
if(idx >= 0 && num === i) {
148148
start = withHL.substring(0, idx)
149149
if(idx + untagged.length <= withHL.length) end = withHL.substring(idx + untagged.length)
@@ -220,7 +220,7 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
220220
const newShow = {}
221221
out = []
222222
let tag = "note"
223-
for(const name of ["seriesName", "summary", "comment", "authorshipStatement" /*, "authorName"*/]) {
223+
for(const name of ["seriesName", "summary", "comment", "authorshipStatement", "authorName"]) {
224224
if(labels[name]?.length) {
225225
const byLang = labels[name].reduce((acc,l) => ({
226226
...acc,
@@ -229,9 +229,13 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
229229

230230
//console.log("byL:", byLang, labels[name])
231231

232-
const hasMatchInLang = Object.values(byLang).some(b => b.includes("↦"))
232+
if(name === "authorName") {
233+
const matchingAuthorNames = labels[name].filter(n => n.value?.includes("↦")).map(n => (sortLangScriptLabels([{value:n.value,lang:n.lang}],langs.flat,langs.translit)??[])[0]).map(n => ({...n,k:n.value.replace(/[]/g,"").replace(/(^ +)|( +$)/g,"")}))
234+
setAuthorName(matchingAuthorNames)
235+
continue;
236+
}
233237

234-
const sortLabels = sortLangScriptLabels(Object.keys(byLang).filter(k => !hasMatchInLang || byLang[k]?.includes("↦")).map(k => ({lang:k, value:byLang[k]})),langs.flat,langs.translit)
238+
const sortLabels = sortLangScriptLabels(Object.keys(byLang).map(k => ({lang:k, value:byLang[k]})),langs.flat,langs.translit)
235239

236240
if(hidden_if_no_match_and_not_locale_en.includes(name) && sortLabels.length && !sortLabels[0].value?.includes("↦") && (!sortLabels[0].lang.startsWith("en") || that.props.locale != "en")) continue;
237241

@@ -275,9 +279,9 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
275279
} else if(name === "authorshipStatement") {
276280
setAuthorshipStatement(out)
277281
out = []
278-
tag = "authorName"
279-
} else if(name === "authorName") {
280-
setAuthorName(out)
282+
// tag = "authorName"
283+
//} else if(name === "authorName") {
284+
// setAuthorName(out)
281285
} else if(name === "seriesName") {
282286
if(out.length) setSeriesName(out)
283287
out = []
@@ -441,6 +445,20 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
441445
if(top) top.scrollIntoView()
442446
}
443447

448+
const memoAuthors = useMemo(() => (
449+
(hit.author ?? []) //.concat(hit.translator ?? [])
450+
.map(a => {
451+
const label = getPropLabel(that, fullUri("bdr:"+a), true, true, "", 1, storage, true, authorName) ?? a
452+
453+
return (<span data-id={a}>
454+
{/* <Link to={"/show/bdr:"+a+backLink}> */}
455+
{ label }
456+
{/* </Link> */}
457+
</span>)
458+
}
459+
)
460+
), [hit.author, storage, authorName])
461+
444462
return (<div class={"result "+hit.type}>
445463
<div class="main">
446464
<Link to={link} className="BG-link" onClick={scrollToTop}></Link>
@@ -538,19 +556,7 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
538556
<span class="label">{I18n.t("result.workBy")}<span class="colon">:</span></span>
539557
<span>
540558
<span className="author-links">
541-
{false && authorName ?
542-
<span>{authorName}</span>
543-
: (hit.author ?? []) //.concat(hit.translator ?? [])
544-
.map(a => {
545-
return (<span data-id={a}>
546-
{/* <Link to={"/show/bdr:"+a+backLink}> */}
547-
{
548-
getPropLabel(that, fullUri("bdr:"+a), true, true, "", 1, storage, true) ?? a
549-
}
550-
{/* </Link> */}
551-
</span>)
552-
}
553-
)}
559+
{ memoAuthors }
554560
</span>
555561
{ authorshipStatement.length > 0 && <span className="authorship">
556562
{ authorshipStatement }
@@ -559,7 +565,18 @@ const CustomHit = ({ hit, routing, that, sortItems, recent, storage, advanced /*
559565
</span>
560566
</span>
561567
}
562-
568+
569+
{/* // debug
570+
authorName && <span class="names author noNL">
571+
<span class="label">{I18n.t("result.workBy")}<span class="colon">:</span></span>
572+
<span>
573+
<span className="author-links">
574+
{ authorName && <span>{JSON.stringify(authorName)}</span> }
575+
</span>
576+
</span>
577+
</span>
578+
*/}
579+
563580
{
564581
isMetaMatch && nbEtextHits > 0 && <span class="names">
565582
<span class="label">{I18n.t("result.nHitET", {count: nbEtextHits})}<span class="colon">:</span></span>

src/lib/searchkit/pages/Search.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,11 @@ export class SearchPage extends Component<State, Props>
449449

450450
const toggleIsFocused = () => this.setState({collapse:{...this.state.collapse, isFocused:!this.state.collapse.isFocused}})
451451

452+
const scrollToTop = () => {
453+
const top = document.querySelector("#root > .over-nav")
454+
if(top) top.scrollIntoView()
455+
}
456+
452457
return (
453458
<>
454459
{ top_right_menu(this,null,null,null,null,this.props.location) }
@@ -504,7 +509,7 @@ export class SearchPage extends Component<State, Props>
504509
</div>
505510
<Configure hitsPerPage={window.innerWidth <= 665 ? 20 : 20} filters={pageFilters} />
506511
<HitsWithLabels that={this} {...{ routing, sortItems, storageRef }} />
507-
<div className="pagination">
512+
<div className="pagination" onClick={scrollToTop}>
508513
<Pagination padding={window.innerWidth <= 665 ? 1 : 3}/>
509514
</div>
510515
</div>

src/lib/transliterators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const transliterators = {
8888
"km":{ "km-x-iast": (val) => Sanscript.t(val,"khmer","iast") },
8989
"km-x-iast":{ "km": (val) => Sanscript.t(val,"iast","khmer") },
9090

91-
// for new search results
91+
// quickfix for new search results
9292

9393
"hani":{
9494
"zh-latn-pinyin" : (val) => pinyin4js.convertToPinyinString(val, ' ', pinyin4js.WITH_TONE_MARK) ,

0 commit comments

Comments
 (0)