brief: | i18n.site tsopano imathandizira kusaka kwamalemba athunthu opanda seva.
Nkhaniyi ikuwonetsa kukhazikitsidwa kwaukadaulo waukadaulo wamawu akutsogolo, kuphatikiza indexedDB yopangidwa ndi indexedDB, kusaka kwachiyambi, kukhathamiritsa kwa magawo a mawu komanso kuthandizira zilankhulo zambiri.
Poyerekeza ndi mayankho omwe alipo, kusaka koyera kutsogolo kwa i18n.site ndikocheperako komanso mwachangu, koyenera mawebusayiti ang'onoang'ono ndi apakatikati monga zolemba ndi mabulogu, ndipo amapezeka popanda intaneti.
& pa chitukuko cha masabata angapo markdown i18n.site
Nkhaniyi igawana zaukadaulo wa i18n.site
kusaka kwathunthu-kumapeto i18n.site kuti mumve zakusaka.
Khodi gwero : fufuzani kernel / yolumikizirana
Kwa mawebusayiti ang'onoang'ono ndi apakatikati omwe ali ngati zikalata / mabulogu anu, kupanga zolemba zodzipangira nokha ndizolemera kwambiri, ndipo kusaka mawu athunthu kopanda ntchito ndikomwe kofala.
Mayankho osakira mawu opanda seva amagwera m'magulu awiri:
Choyamba, ofanana algolia.com
Ntchito zotere zimafunikira kulipira kutengera kuchuluka kwakusaka, ndipo nthawi zambiri sapezeka kwa ogwiritsa ntchito ku China chifukwa chazovuta monga kutsata tsamba lawebusayiti.
Sichingagwiritsidwe ntchito pa intaneti, sichingagwiritsidwe ntchito pa intaneti, ndipo chili ndi malire aakulu. Nkhaniyi sifotokoza zambiri.
Chachiwiri ndikufufuza mawu athunthu.
Pakadali pano, kusaka kodziwika lunrjs komaliza kumaphatikizapo ElasticLunr.js (kutengera chitukuko lunrjs
).
lunrjs
Pali njira ziwiri zopangira ma index, ndipo onse ali ndi zovuta zawo.
Mafayilo opangidwa kale
Chifukwa mlozerawu uli ndi mawu ochokera m'malemba onse, ndi wamkulu mu kukula kwake. Nthawi zonse chikalata chiwonjezedwa kapena kusinthidwa, fayilo yatsopano ya index iyenera kukwezedwa. Idzawonjezera nthawi yodikira ya wogwiritsa ntchito ndikuwononga bandwidth yambiri.
Kwezani zikalata ndi kupanga indexes pa ntchentche
Kupanga index ndi ntchito yovuta kwambiri yomanganso index nthawi iliyonse mukafika kumapangitsa kuti pakhale kusakhazikika komanso kusazindikira bwino kwa ogwiritsa ntchito.
Kuphatikiza pa lunrjs
, palinso mayankho ena athunthu, monga :
fusejs , werengerani kufanana pakati pa zingwe kuti mufufuze.
Magwiridwe a yankholi ndiwoyipa kwambiri ndipo sangathe kugwiritsidwa ntchito posaka mawu athunthu (onani Fuse.js Kufunsa kwautali kumatenga kupitilira masekondi 10 , mungakulitsitse bwanji? ).
TinySearch , gwiritsani ntchito fyuluta ya Bloom kuti mufufuze, siingagwiritsidwe ntchito pakusaka kwachiyambi (mwachitsanzo, lowetsani goo
, fufuzani good
, google
), ndipo simungathe kukwaniritsa zotsatira zofananazo.
Chifukwa cha zolakwika za mayankho omwe alipo, i18n.site
adapanga njira yatsopano yosakira mawu, yomwe ili ndi zotsatirazi :
gzip
ndi 6.9KB
(poyerekeza, kukula kwa lunrjs
ndi 25KB
)indexedb
, yomwe imatenga kukumbukira pang'ono komanso mwachangu.Pansipa, i18n.site
tsatanetsatane waukadaulo waukadaulo adzafotokozedwa mwatsatanetsatane.
Kugawanika kwa mawu kumagwiritsa ntchito gawo la mawu a msakatuli Intl.Segmenter
, ndipo asakatuli onse akuluakulu amathandizira mawonekedwe awa.
Mawu akuti segmentation coffeescript
code ali motere
SEG = new Intl.Segmenter 0, granularity: "word"
seg = (txt) =>
r = []
for {segment} from SEG.segment(txt)
for i from segment.split('.')
i = i.trim()
if i and !'| `'.includes(i) and !/\p{P}/u.test(i)
r.push i
r
export default seg
export segqy = (q) =>
seg q.toLocaleLowerCase()
mu:
/\p{P}/
ndi mawu okhazikika omwe amafanana ndi zizindikiro zofananira ndi izi: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _
{ | } ```.
split('.')
ndi chifukwa Firefox
msakatuli segmentation mawu alibe gawo .
.Matebulo osungira zinthu 5 adapangidwa mu IndexedDB
:
word
: id -doc
: id - Document url - Nambala ya mtundu wa DocumentdocWord
Mndandanda : id - mawu idprefix
: Mndandanda wa mawu oyambira - idrindex
: id - Document id : Mndandanda wa manambala a mzerePitani pamndandanda wa chikalata url
ndi mtundu ver
, ndipo fufuzani ngati chikalatacho chili patebulo doc
Ngati sichipezeka, pangani index inverted. Nthawi yomweyo, chotsani index inverted ya zolemba zomwe sizinalowe.
Mwanjira iyi, kuwonjezereka kwa indexing kumatha kutheka ndipo kuchuluka kwa kuwerengera kumachepetsedwa.
Kumapeto kwakumapeto, cholozera cholozera chikhoza kuwonetsedwa kuti musachedwe progress + css kwa / yoyamba .
Pulojekitiyi idb kutengera kusungidwa kwa asynchronous kwa IndexedDB
IndexedDB amawerenga ndikulemba ndi asynchronous. Mukapanga index, zolemba zimayikidwa nthawi imodzi kuti mupange index.
Kuti mupewe kutayika pang'ono kwa data chifukwa cha kulemba kwapikisano, mutha kulozera ku code coffeescript
pansipa ndikuwonjezera ing
cache pakati pa kuwerenga ndi kulemba kuti mupewe zolemba zopikisana.
pusher = =>
ing = new Map()
(table, id, val)=>
id_set = ing.get(id)
if id_set
id_set.add val
return
id_set = new Set([val])
ing.set id, id_set
pre = await table.get(id)
li = pre?.li or []
loop
to_add = [...id_set]
li.push(...to_add)
await table.put({id,li})
for i from to_add
id_set.delete i
if not id_set.size
ing.delete id
break
return
rindexPush = pusher()
prefixPush = pusher()
Kusakaku kudzakhala gawo loyamba la mawu osakira omwe alowetsedwa ndi wogwiritsa ntchito.
Tangoganizani kuti pali mawu N
pambuyo pa gawo la mawu pobweretsa zotsatira, zotsatira zomwe zili ndi mawu osakira zidzabwezedwa koyamba, kenako zotsatira zomwe zili ndi N-1
, N-2
,..., 1
mawu osakira.
Zotsatira zosaka zomwe zimawonetsedwa koyamba zimatsimikizira kulondola kwa funsolo, ndipo zotsatira zomwe zimayikidwa pambuyo pake (dinani batani lowonjezera) zitsimikizire kuchuluka kwa kukumbukira.
Pofuna kuwongolera liwiro la kuyankha, kusaka kumagwiritsa ntchito jenereta yield
kuti akwaniritse zomwe akufuna, ndipo amabwerera nthawi limit
zotsatira zikafunsidwa.
Dziwani kuti nthawi iliyonse mukasakanso pambuyo pa yield
, muyenera kutsegulanso funso la IndexedDB
.
Kuti muwonetse zotsatira zakusaka pamene wogwiritsa ntchito akulemba, mwachitsanzo, wor
akalowa, mawu omwe ali ndi wor
monga words
ndi work
amawonetsedwa.
Kernel yofufuzira idzagwiritsa ntchito tebulo prefix
pa liwu lomaliza pambuyo pa gawo la mawu kuti mupeze mawu onse omwe ali nawo, ndikufufuza motsatizana.
Ntchito yotsutsana ndi kugwedeza debounce
imagwiritsidwanso ntchito pakugwirizanitsa kutsogolo (kukhazikitsidwa motere) kuti achepetse kuchuluka kwa zolowera zomwe zimayambitsa kusaka ndikuchepetsa kuchuluka kwa kuwerengera.
export default (wait, func) => {
var timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(func.bind(this, ...args), wait);
};
}
Gome la ndondomeko silisunga malemba oyambirira, mawu okha, omwe amachepetsa kusungirako.
Kuwunikira zotsatira kumafuna kuti mutsitsenso mawu oyamba, ndipo kufananitsa service worker
kungapewe kufunsidwa mobwerezabwereza.
Nthawi yomweyo, chifukwa service worker
imasunga zolemba zonse, wogwiritsa ntchito akangofufuza, tsamba lonselo, kuphatikiza kusaka, limapezeka popanda intaneti.
i18n.site
's pure-end-end search solution imakongoletsedwa ndi zolemba MarkDown
.
Mukawonetsa zotsatira zakusaka, dzina lamutu lidzawonetsedwa ndipo mutuwo udzawunikidwa mukadina.
Kusaka kwa mawu otembenuzidwa kumayendetsedwa kumapeto kwenikweni, palibe seva yofunikira. Ndizoyenera kwambiri mawebusayiti ang'onoang'ono komanso apakatikati monga zolemba ndi mabulogu anu.
i18n.site
Kusaka kotseguka kodzipangira koyambirira, kocheperako kukula komanso kuyankha mwachangu, kumathetsa zophophonya zakusaka kwapamapeto akutsogolo komanso kumapereka chidziwitso cha ogwiritsa ntchito.