brief: | i-i18n.site manje isekela ukusesha kombhalo ogcwele okungenasiphakeli.
Lesi sihloko sethula ukuqaliswa kobuchwepheshe bokusesha bombhalo ophelele ophelele osekupheleni, okuhlanganisa inkomba ehlanekezelwe eyakhiwe yi-IndexedDB, ukusesha kwesiqalo, ukuthuthukiswa kwesegmentation yamagama nokusekelwa kwezilimi eziningi.
Uma kuqhathaniswa nezixazululo ezikhona, ukusesha kwe-i18n.site kombhalo ophelele okumsulwa kuncane ngosayizi futhi kuyashesha, kufanelekile kumawebhusayithi amancane namaphakathi afana nemibhalo namabhulogi, futhi kuyatholakala ungaxhunyiwe ku-inthanethi.
Ngemva kwamaviki ambalwa okuthuthuka, i18n.site (ithuluzi lokwakha & elimile markdown multilingualtranslation) manje lisekela ukusesha kombhalo ophelele okugcwele.
Lesi sihloko sizokwabelana ngokusetshenziswa kobuchwepheshe bosesho oluphelele lombhalo ophelele ongu i18n.site
i18n.site ukuze uthole umphumela wosesho.
Ikhodi yomthombo ovulekile : Sesha isikhombimsebenzisi esibonakalayo / esisebenzayo
Kumawebhusayithi amancane naphakathi nendawo amile njengamadokhumenti/amabhulogi omuntu siqu, ukwakha isizinda sokusesha sombhalo ogcwele esakhelwe wena kusinda kakhulu, futhi ukusesha umbhalo ogcwele okungenasevisi kuyisinqumo esivame kakhulu.
Izixazululo zokusesha umbhalo ogcwele ezingenaseva ziwela ezigabeni ezimbili ezibanzi:
Okokuqala, okufanayo algolia.com
Amasevisi anjalo adinga inkokhelo esekelwe kumthamo wokusesha, futhi ngokuvamile awatholakali kubasebenzisi base-Mainland China ngenxa yezinkinga ezifana nokuthobela iwebhusayithi.
Ngeke isetshenziswe ungaxhunyiwe ku-inthanethi, ayikwazi ukusetshenziswa ku-intranethi, futhi inemikhawulo emikhulu. Lesi sihloko asixoxi okuningi.
Okwesibili usesho lombhalo ogcwele osekupheleni.
Njengamanje, usesho olujwayelekile lunrjs
ogcwele ophelele ElasticLunr.js luhlanganisa lunrjs
lunrjs
Kunezindlela ezimbili zokwakha izinkomba, futhi zombili zinezinkinga zazo.
Amafayela enkomba akhiwe ngaphambilini
Ngenxa yokuthi inkomba iqukethe amagama avela kuyo yonke imibhalo, inkulu ngosayizi. Noma nini lapho idokhumenti yengezwa noma ilungiswa, ifayela elisha lenkomba kufanele lilayishwe. Kuzokwandisa isikhathi sokulinda somsebenzisi futhi kudle umkhawulokudonsa omningi.
Layisha amadokhumenti futhi wakhe izinkomba ngokuhamba kwesikhathi
Ukwakha inkomba kuwumsebenzi onzima wekhompyutha Ukwakha kabusha inkomba njalo uma ufinyelela kuyo kuzobangela ukubambezeleka okusobala kanye nolwazi olubi lomsebenzisi.
Ngokungeziwe kokuthi lunrjs
, kunezinye izixazululo zokusesha zombhalo ogcwele, njengokuthi :
fusejs , bala ukufana phakathi kwezintambo zokusesha.
Ukusebenza kwalesi sixazululo kumbi kakhulu futhi akukwazi ukusetshenziselwa ukusesha umbhalo ogcwele (bheka Fuse.js Umbuzo omude uthatha ngaphezu kwamasekhondi angu- 10 , ungawulungiselela kanjani? ).
TinySearch sebenzisa isihlungi se-Bloom ukusesha, asikwazi ukusetshenziselwa ukusesha isiqalo (isibonelo, faka goo
, sesha good
, google
), futhi awukwazi ukuzuza umphumela ofanayo wokuqedela ozenzakalelayo.
Ngenxa yokushiyeka kwezixazululo ezikhona, i18n.site
uthuthukise isixazululo esisha sombhalo ophelele esihlanzekile, esinezici ezilandelayo :
gzip
ngu- 6.9KB
(uma kuqhathaniswa, usayizi ka- lunrjs
ngu- 25KB
)indexedb
, ethatha inkumbulo encane futhi esheshayo.Ngezansi, imininingwane engu i18n.site
yokuqalisa ukusebenza izokwethulwa ngokuningiliziwe.
Ukuhlukaniswa kwegama kusebenzisa ingxenye yegama lesiphequluli elingu Intl.Segmenter
, futhi zonke iziphequluli ezivamile zisekela lesi sixhumanisi.
Igama elithi segmentation coffeescript
code limi kanje
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()
ku:
/\p{P}/
isisho esivamile esihambisana nezimpawu zokubhala eziqondile zifaka: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _
{ | } . .</p><ul><li>
split('.')kungenxa yokuthi ukuhlukaniswa kwegama lesiphequluli esi
Firefoxakunayo ingxenye yesi
. ` .
5 amathebula okugcina izinto adalwe ngo IndexedDB
:
word
: id -doc
: id - Idokhumenti url - Inombolo yenguqulodocWord
: lwedokhumenti id - igama idprefix
: lwesiqalo - igama idrindex
: IZwi id - Idokhumenti id : Uhlu lwezinombolo zomugqaDlula ohlwini lwedokhumenti url
kanye nenombolo yenguqulo ver
, bese ucinga ukuthi ingabe idokhumenti ikhona yini kuthebula lesi- doc
Uma ingekho, yakha inkomba ehlanekezelwe. Ngesikhathi esifanayo, susa inkomba ehlanekezelwe yalawo madokhumenti angazange adluliselwe kuwo.
Ngale ndlela, ukukhomba okukhuphukayo kungafinyelelwa futhi nenani lokubala liyancishiswa.
Ekuhlanganyeleni okungaphambili, ibha yenqubekelaphambili yokulayisha yenkomba ingaboniswa ukuze kugwenywe ukunensa lapho kulayishwa okokuqala ngqa Bona "Ibha Yenqubekelaphambili Enopopayi, Isekelwe Kokukodwa progress + Pure css Implementation" English / Chinese .
Iphrojekthi idb ngokusekelwe ekuhlanganisweni kwe-asynchronous IndexedDB
I-IndexedDB ifunda futhi ibhale asynchronous. Lapho udala inkomba, amadokhumenti azolayishwa kanyekanye ukuze kwakhiwe inkomba.
Ukuze ugweme ukulahleka kwedatha okuyingxenye okubangelwa ukubhala ngokuncintisana, ungabheka ikhodi coffeescript
engezansi bese wengeza inqolobane ing
phakathi kokufunda nokubhala ukuze unqande ukubhala okuncintisanayo.
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()
Usesho luzoqala luhlukanise amagama angukhiye afakwe umsebenzisi.
Cabanga ukuthi kunamagama angu N
ngemva kwesegimenti yamagama Uma ubuyisela imiphumela, imiphumela equkethe wonke amagama angukhiye izobuyiswa kuqala, bese kulandela imiphumela equkethe N-1
, N-2
,..., 1
amagama angukhiye.
Imiphumela yosesho eboniswa kuqala iqinisekisa ukunemba kombuzo, futhi imiphumela elayishwa kamuva (chofoza inkinobho yokulayisha ngaphezulu) iqinisekisa izinga lokukhumbula.
Ukuze kuthuthukiswe isivinini sokuphendula, usesho lusebenzisa ijeneretha yield
ukuze luqalise ukulayisha okudingekayo, futhi lubuyisela limit
uma umphumela ubuzwa.
Qaphela ukuthi isikhathi ngasinye uma usesha futhi ngemva kuka yield
, udinga ukuvula kabusha umsebenzi woku- IndexedDB
.
Ukuze ubonise imiphumela yosesho ngenkathi umsebenzisi ebhala, isibonelo, uma kufakwa wor
, amagama aqanjwe ngo wor
njengo words
no work
ayavezwa.
I-kernel yosesho izosebenzisa ithebula prefix
legama lokugcina ngemva kokuhlukaniswa kwegama ukuze kutholwe wonke amagama aqanjwe ngawo, bese kusesha ngokulandelana.
Umsebenzi we-anti-shake ongu debounce
nawo usetshenziswa ekuxhumaneni okungaphambili (kusetshenziswe ngendlela elandelayo) ukuze kuncishiswe imvamisa yokufaka komsebenzisi okubangela usesho nokunciphisa inani lokubala.
export default (wait, func) => {
var timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(func.bind(this, ...args), wait);
};
}
Ithebula lenkomba aligcini umbhalo wokuqala, amagama kuphela, okunciphisa inani lokulondoloza.
Ukugqamisa imiphumela yosesho kudinga ukuphinda kulayishwe umbhalo wokuqala, futhi ukufanisa service worker
kungagwema izicelo eziphindaphindiwe zenethiwekhi.
Ngesikhathi esifanayo, ngenxa yokuthi service worker
ugcina zonke iziqephu zendatshana, uma umsebenzisi esesheshile, yonke iwebhusayithi, okuhlanganisa nosesho, iyatholakala ungaxhunyiwe ku-inthanethi.
i18n.site
's isixazululo esihlanzekile sokusesha senzelwe amadokhumenti MarkDown
.
Uma ubonisa imiphumela yosesho, igama lesahluko lizovezwa futhi isahluko sizozulazulwa lapho ichofozwa.
Usesho lombhalo ogcwele ohlanekezelwe lusetshenziswe ekuqaleni kuphela, asikho iseva edingekayo. Ifaneleka kakhulu kumawebhusayithi amancane naphakathi afana nemibhalo namabhulogi omuntu siqu.
i18n.site
Umthombo ovulekile usesho lwangaphambili oluhlanzekile, oluncane ngosayizi nokuphendula ngokushesha, luxazulula ukushiyeka kosesho olugcwele lwamanje lwangaphambili oluphelele futhi lunikeza ulwazi olungcono lomsebenzisi.