cjk_index 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +15 -10
- data/lib/cjk_index/jekyll.rb +11 -2
- data/lib/cjk_index/normalizer.rb +13 -5
- data/lib/cjk_index/runtime.js +10 -0
- data/lib/cjk_index/searcher.rb +6 -2
- data/lib/cjk_index/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d360872de9c0b91daee9a5c74034fbdda1f4013be23018added03567c44ce8a
|
|
4
|
+
data.tar.gz: f3629c78f9e73291d6d6f7b2697705f4b639835e5142b3897be7e17f7e861552
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82646c281e575cf065d6ec78e2f568864e795e20353f425a73931202264b7de47dc794757299adf4a42e2547a16413f7e67e1f814b8544b088984957a71dda50
|
|
7
|
+
data.tar.gz: 727c2f0aac48eedfa8f0d04bad65ce28c4b4cc918d9c1053a6a5f7a39f0505cb00603c310616b5496e87d3028caa674bcc88646e57687a5ebec8222c4b48adbe
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.2 (2026-11-14)
|
|
4
|
+
|
|
5
|
+
- Jekyll: on a CollectionBuilder site (one with `_data/config-search.csv`),
|
|
6
|
+
the `search` index with `preset: collectionbuilder` and `variants: [ja]` is
|
|
7
|
+
built by default when `_config.yml` has no `cjk_index` section (or when
|
|
8
|
+
`cjk_index` sets only options such as `variants`). Set `cjk_index: false`
|
|
9
|
+
(or `enabled: false`) to turn it off.
|
|
10
|
+
|
|
11
|
+
## 1.1.1 (2026-10-28)
|
|
12
|
+
|
|
13
|
+
- Variation selectors (U+FE00–U+FE0F and the ideographic U+E0100–U+E01EF)
|
|
14
|
+
are dropped when folding: 「珊」 followed by an ideographic variation
|
|
15
|
+
selector is 「珊」. Before, the selector broke a CJK run in two, so
|
|
16
|
+
「珊瑚」 did not find 「珊\u{E0100}瑚」, and a table file of your own with
|
|
17
|
+
such a cell was rejected as "not one character". `highlight` and
|
|
18
|
+
`excerpt` keep the selector inside the mark with its character. Rebuild
|
|
19
|
+
indexes whose text has variation selectors.
|
|
20
|
+
|
|
3
21
|
## 1.1.0 (2026-10-28)
|
|
4
22
|
|
|
5
23
|
- `variants` also takes table files of your own: one group per line,
|
data/README.md
CHANGED
|
@@ -24,8 +24,8 @@ even when it is an exact title. cjk_index instead:
|
|
|
24
24
|
stores their positions, so a query matches only where its bigrams are
|
|
25
25
|
adjacent and in order: an exact substring match, with no dictionary or
|
|
26
26
|
native extension (the same idea as [kensaku](https://github.com/whispcat/kensaku));
|
|
27
|
-
- folds variants on both sides: NFKC, lowercase,
|
|
28
|
-
old-form kanji → modern form (「圖」→「図」), 々 expanded (「佐々木」→「佐佐木」),
|
|
27
|
+
- folds variants on both sides: NFKC, lowercase, variation selectors
|
|
28
|
+
dropped, katakana → hiragana, old-form kanji → modern form (「圖」→「図」), 々 expanded (「佐々木」→「佐佐木」),
|
|
29
29
|
and optionally Traditional ↔ Simplified Chinese (from OpenCC) and old
|
|
30
30
|
Hangul in the Private Use Area;
|
|
31
31
|
- ranks with BM25 per field, with field boosts;
|
|
@@ -39,7 +39,7 @@ even when it is an exact title. cjk_index instead:
|
|
|
39
39
|
- splits a large index into a small manifest and shards that the browser
|
|
40
40
|
fetches only when a query needs them.
|
|
41
41
|
|
|
42
|
-
The browser script is about
|
|
42
|
+
The browser script is about 11 KB gzipped with the Japanese table, 28 KB
|
|
43
43
|
with the Chinese table as well. Index it from Ruby, Jekyll, Bridgetown, a
|
|
44
44
|
Rake task or the command line.
|
|
45
45
|
|
|
@@ -256,11 +256,14 @@ lunr.js: [docs/migrating-from-lunr.md](docs/migrating-from-lunr.md).
|
|
|
256
256
|
|
|
257
257
|
### CollectionBuilder
|
|
258
258
|
|
|
259
|
+
On a CollectionBuilder site (one with `_data/config-search.csv`), adding the
|
|
260
|
+
gem to `Gemfile` is enough: `assets/cjk-index/search.json` is built by default
|
|
261
|
+
with `preset: collectionbuilder` and `variants: [ja]`. Set `cjk_index:` in
|
|
262
|
+
`_config.yml` only to change options such as `variants`:
|
|
263
|
+
|
|
259
264
|
```yaml
|
|
260
265
|
cjk_index:
|
|
261
|
-
|
|
262
|
-
- name: search
|
|
263
|
-
preset: collectionbuilder
|
|
266
|
+
variants: [ja, zh]
|
|
264
267
|
```
|
|
265
268
|
|
|
266
269
|
The preset follows CollectionBuilder's own search settings: fields with
|
|
@@ -386,8 +389,10 @@ cjk_index:
|
|
|
386
389
|
variants: [ja, _data/itaiji.tsv]
|
|
387
390
|
```
|
|
388
391
|
|
|
389
|
-
Each cell is folded first (NFKC, lowercase,
|
|
390
|
-
|
|
392
|
+
Each cell is folded first (NFKC, lowercase, variation selectors dropped,
|
|
393
|
+
katakana → hiragana), so a cell written as an ideographic variation sequence
|
|
394
|
+
(珊 + U+E0100) is the character itself, and the table listed first still
|
|
395
|
+
picks the form a group folds to. The index records
|
|
391
396
|
the entry as written (`_data/itaiji.tsv`), not the full path, and its digest
|
|
392
397
|
covers the file's contents, so editing the file means rebuilding the index.
|
|
393
398
|
To read such an index from another folder in Ruby, pass the normalizer:
|
|
@@ -395,8 +400,8 @@ To read such an index from another folder in Ruby, pass the normalizer:
|
|
|
395
400
|
Wide lists merge more than spelling: a list that puts 燕 with 宴 makes
|
|
396
401
|
a search for 燕 (swallow) find 宴 (banquet). Check a list against your own material first.
|
|
397
402
|
|
|
398
|
-
Browser script size, gzipped
|
|
399
|
-
|
|
403
|
+
Browser script size, gzipped (level 9, 1.1.1; KB = 1,024 bytes): no table
|
|
404
|
+
8.8 KB, `ja` 11.4 KB, `ja, zh-safe` 26.2 KB, `ja, zh` 27.8 KB, `ja, ko` 38.0 KB.
|
|
400
405
|
|
|
401
406
|
The tables are UTF-8 TSV files in `data/` ("variant<TAB>folded", an optional
|
|
402
407
|
comment column, `#` comments); `script/variant_tables.rb` generates them from
|
data/lib/cjk_index/jekyll.rb
CHANGED
|
@@ -37,6 +37,7 @@ module CJKIndex
|
|
|
37
37
|
module Jekyll
|
|
38
38
|
DEFAULT_OUTPUT = "assets/cjk-index"
|
|
39
39
|
RUNTIME_NAME = "cjk-index.js"
|
|
40
|
+
CB_DEFAULT_INDEXES = [{ "name" => "search", "preset" => "collectionbuilder" }].freeze
|
|
40
41
|
|
|
41
42
|
# A file whose content is produced at build time (no source file, no Liquid).
|
|
42
43
|
class GeneratedFile < ::Jekyll::StaticFile
|
|
@@ -61,12 +62,20 @@ module CJKIndex
|
|
|
61
62
|
|
|
62
63
|
def generate(site)
|
|
63
64
|
config = site.config["cjk_index"]
|
|
64
|
-
|
|
65
|
+
config = {} if config.nil? && site.data.key?("config-search")
|
|
66
|
+
return unless config.is_a?(Hash) && config["enabled"] != false
|
|
65
67
|
|
|
66
68
|
output = config.fetch("output", DEFAULT_OUTPUT).sub(%r{\A/+}, "").sub(%r{/+\z}, "")
|
|
67
69
|
normalizer = Normalizer.new(tables: Array(config.fetch("variants", Normalizer::DEFAULT_TABLES)), base: site.source)
|
|
68
70
|
site.static_files << GeneratedFile.new(site, output, RUNTIME_NAME, Runtime.source(normalizer: normalizer))
|
|
69
|
-
|
|
71
|
+
indexes = if config.key?("indexes")
|
|
72
|
+
Array(config["indexes"])
|
|
73
|
+
elsif site.data.key?("config-search")
|
|
74
|
+
CB_DEFAULT_INDEXES
|
|
75
|
+
else
|
|
76
|
+
[]
|
|
77
|
+
end
|
|
78
|
+
indexes.each do |spec|
|
|
70
79
|
builder = build(site, spec, normalizer)
|
|
71
80
|
if spec["split"]
|
|
72
81
|
dir = "#{output}/#{spec.fetch('name')}"
|
data/lib/cjk_index/normalizer.rb
CHANGED
|
@@ -5,9 +5,10 @@ require "json"
|
|
|
5
5
|
|
|
6
6
|
module CJKIndex
|
|
7
7
|
# Folds text so that spelling variants a reader treats as "the same" compare
|
|
8
|
-
# equal: NFKC (full-width -> half-width etc.), lowercase,
|
|
9
|
-
#
|
|
10
|
-
#
|
|
8
|
+
# equal: NFKC (full-width -> half-width etc.), lowercase, variation
|
|
9
|
+
# selectors dropped (珊 followed by an ideographic variation selector is 珊),
|
|
10
|
+
# katakana -> hiragana, character variants from the selected tables, and
|
|
11
|
+
# the iteration mark 々 expanded to the preceding character.
|
|
11
12
|
#
|
|
12
13
|
# The same rules run in the browser (see Runtime), so an index built here
|
|
13
14
|
# and a query typed there are folded identically.
|
|
@@ -52,6 +53,11 @@ module CJKIndex
|
|
|
52
53
|
KATAKANA_LAST = 0x30F6
|
|
53
54
|
KANA_OFFSET = 0x60
|
|
54
55
|
ITERATION_MARK = "々"
|
|
56
|
+
# Variation selectors (VS1-VS16 and the ideographic VS17-VS256) only pick
|
|
57
|
+
# a glyph of the character before them: 珊 with or without U+E0100 is the
|
|
58
|
+
# same character to a reader, so they are dropped, not kept as a run of
|
|
59
|
+
# their own between two CJK characters. In String#delete form.
|
|
60
|
+
VARIATION_SELECTORS = "\u{FE00}-\u{FE0F}\u{E0100}-\u{E01EF}"
|
|
55
61
|
|
|
56
62
|
def self.default
|
|
57
63
|
@default ||= new
|
|
@@ -121,14 +127,16 @@ module CJKIndex
|
|
|
121
127
|
"#{tables.inspect} (an older cjk_index?); rebuild it"
|
|
122
128
|
end
|
|
123
129
|
|
|
124
|
-
# Character by character:
|
|
125
|
-
# then 々 to the (folded) character
|
|
130
|
+
# Character by character: variation selectors dropped, katakana to
|
|
131
|
+
# hiragana, then the variant tables, then 々 to the (folded) character
|
|
132
|
+
# before it. Done as passes over the
|
|
126
133
|
# whole string, which gives the same result as one loop over the
|
|
127
134
|
# characters (the loop in runtime.js) and is several times faster in Ruby.
|
|
128
135
|
def normalize(text)
|
|
129
136
|
return "" if text.nil?
|
|
130
137
|
|
|
131
138
|
s = text.to_s.unicode_normalize(:nfkc).downcase
|
|
139
|
+
s = s.delete(VARIATION_SELECTORS)
|
|
132
140
|
s = s.tr(KATAKANA, HIRAGANA)
|
|
133
141
|
# 々 repeats the folded character before it, which may be several
|
|
134
142
|
# characters (ko): fold one character at a time, as runtime.js does
|
data/lib/cjk_index/runtime.js
CHANGED
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
// Score multiplier for matches found by prefix or typo expansion.
|
|
60
60
|
var EXPANDED = 0.6;
|
|
61
61
|
|
|
62
|
+
// Variation selectors (VS1-VS16, VS17-VS256): dropped, as
|
|
63
|
+
// CJKIndex::Normalizer::VARIATION_SELECTORS in Ruby.
|
|
64
|
+
var SELECTOR = /^[\ufe00-\ufe0f\u{e0100}-\u{e01ef}]$/u;
|
|
65
|
+
|
|
62
66
|
// Folds one character; prev is the previous folded character (for 々).
|
|
63
67
|
function foldChar(ch, prev) {
|
|
64
68
|
var c = ch.codePointAt(0);
|
|
@@ -73,6 +77,7 @@
|
|
|
73
77
|
var out = '';
|
|
74
78
|
var prev = null;
|
|
75
79
|
for (var ch of String(text).normalize('NFKC').toLowerCase()) {
|
|
80
|
+
if (SELECTOR.test(ch)) continue;
|
|
76
81
|
prev = foldChar(ch, prev);
|
|
77
82
|
out += prev;
|
|
78
83
|
}
|
|
@@ -534,11 +539,16 @@
|
|
|
534
539
|
// Each folded code point remembers which original characters it came
|
|
535
540
|
// from. A character may fold to several (ko: one Private Use Area
|
|
536
541
|
// character -> a jamo sequence), and a cluster may compose into fewer.
|
|
542
|
+
// A character that folds to nothing (a variation selector) belongs to
|
|
543
|
+
// the one before it: a match on 珊 marks its selector too.
|
|
537
544
|
function emit(str, from, to) {
|
|
545
|
+
var before = norm.length;
|
|
538
546
|
for (var c of str.normalize('NFKC').toLowerCase()) {
|
|
547
|
+
if (SELECTOR.test(c)) continue;
|
|
539
548
|
prev = foldChar(c, prev);
|
|
540
549
|
for (var p of prev) { norm.push(p); start.push(from); end.push(to); }
|
|
541
550
|
}
|
|
551
|
+
if (norm.length === before && end.length) end[end.length - 1] = to;
|
|
542
552
|
}
|
|
543
553
|
for (var i = 0, j; i < chars.length; i = j) {
|
|
544
554
|
for (j = i + 1; j < chars.length && JOINS_PREVIOUS.test(chars[j]); j++);
|
data/lib/cjk_index/searcher.rb
CHANGED
|
@@ -353,19 +353,23 @@ module CJKIndex
|
|
|
353
353
|
chars = text.to_s.chars
|
|
354
354
|
norm = +""
|
|
355
355
|
origin = []
|
|
356
|
+
ends = []
|
|
356
357
|
chars.each_with_index do |ch, i|
|
|
357
358
|
folded = normalizer.normalize(ch)
|
|
358
359
|
# 々 depends on the previous character, so fold it in context.
|
|
359
360
|
folded = norm[-1] if folded == Normalizer::ITERATION_MARK && !norm.empty?
|
|
361
|
+
# A character that folds to nothing (a variation selector) belongs to
|
|
362
|
+
# the one before it: a match on 珊 marks its selector too.
|
|
363
|
+
ends[-1] = i + 1 if folded.empty? && !ends.empty?
|
|
360
364
|
norm << folded
|
|
361
|
-
folded.length.times { origin << i }
|
|
365
|
+
folded.length.times { origin << i; ends << i + 1 }
|
|
362
366
|
end
|
|
363
367
|
needles = normalizer.normalize(query).split(Tokenizer::SEPARATOR).reject(&:empty?)
|
|
364
368
|
ranges = needles.flat_map do |needle|
|
|
365
369
|
found = []
|
|
366
370
|
from = 0
|
|
367
371
|
while (at = norm.index(needle, from))
|
|
368
|
-
found << [origin[at],
|
|
372
|
+
found << [origin[at], ends[at + needle.length - 1]]
|
|
369
373
|
from = at + needle.length
|
|
370
374
|
end
|
|
371
375
|
found
|
data/lib/cjk_index/version.rb
CHANGED